我正在尝试在方案中运行这一行:
(let ((x y) (y x)) (设置!x x) (设置!y y))
其中,在程序开始时,x 被定义为 1,y 被定义为 2。 我希望输出为 x=2 和 y=1,但我得到 x=1 和 y=2
感谢您的帮助!
最佳答案
My end goal is to switch their values only with commands, not with temporary variables
看起来 Racket 支持set!-values
,因此您可以交换变量而无需使用任何显式临时变量,如下所示:
(define x 1)
(define y 2)
(set!-values (x y) (values y x))
;;; x is now 2 and y is 1
(甚至是链接文档中的示例)
关于scheme - x 和x 的集合在Scheme 中的let 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65009149/