对 Scheme 中 let 和 let* 之间的区别感到困惑 [英] Confused by the difference between let and let* in Scheme

查看:56
本文介绍了对 Scheme 中 let 和 let* 之间的区别感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能简单解释一下区别?我不认为我从我咨询过的教科书/网站中理解了这个概念.

Can anyone explain the difference simply? I don't think I understand the concept from the textbooks/sites I have consulted.

推荐答案

如果使用 let,则不能引用出现在同一 other 绑定>let 表达式.

If you use let, you can't reference other bindings which appear in the same let expression.

例如,这行不通:

(let ((x 10)
      (y (+ x 6))) ; error! unbound identifier: x
  y)

但是如果你使用 let*,就可能引用出现在同一个 let* 表达式中的 previous 绑定:

But if you use let*, it is possible to refer to previous bindings which appear in the same let* expression:

(let* ((x 10)
       (y (+ x 6))) ; works fine
  y)
=> 16

此处都在文档中.

这篇关于对 Scheme 中 let 和 let* 之间的区别感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆