Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
(let ((x 2) (y 3) (let ((x 7) (z (+ x y))) (* z x)))
使用上面的代码,为什么答案是 35,而不是 70?在第二个let中,x 是 7,所以 z 应该是 7 + 3 = 10,然后结果应该是 7 * 10 = 70。我知道有另一个是 let* 我在这 2 之间很困惑。样本是从谷歌抓取的. 我已经谷歌了,但就是无法得到它。
let
扩展 Leppie 的回答:如果你写过
(let ((x 2) (y 3)) (let* ((x 7) (z (+ x y))) (* z x)))
你会得到你期望的答案。内部let*完全等价于
let*
(let ((x 7)) (let ((z (+ x y))) (* z x)))
实际上可能在某些方案中以这种方式实施。
换句话说,在一个let*表单中,第一个绑定之后的每个后续绑定都在所有先前创建的绑定的范围内。
xlet调用时仍然绑定到外部(+ x y)。
x
(+ x y)