DrRacket 解释器是否使用基于 SICP 练习 1.5 的正态顺序评估?
人们必须根据以下值做出决定:
(测试 0 (p))
其中 test 定义为 :
(define (test x y)
(if (= x 0)
0
y))
并且 p 定义为 :
(define (p) (p))
当我评估 (test 0 (p))
时,解释器进入无限循环,表明它正在评估 <代码>p。这显示了正常顺序求值,因为操作数在替换参数之前先求值。 SICP 表示 LISP 使用应用顺序求值。
One must decide, based on the value of:
(test 0 (p))
where test is defined as :
(define (test x y)
(if (= x 0)
0
y))
and p is defined as :
(define (p) (p))
When I evaluate (test 0 (p))
the interpreter goes into an infinite loop, suggesting that it is evaluating p
. This shows normal-order evaluation, because the operands are evaluated before being substituted for parameters. SICP says LISP uses applicative-order evaluation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
。实际上,您的理解方式是错误的。应用顺序是首先计算操作数的顺序。正常顺序是指将参数代入未计算的表达式中。
因此,球拍使用应用顺序,因为正如您所说,参数首先被评估(除非您使用“Lazy Racket”,在这种情况下,它使用按需调用又名惰性评估,这就像正常顺序,除了每个参数最多评估一次)。
Actually you got it the wrong way around. Applicative order is when the operands are evaluated first. Normal-order is when the arguments are substituted into the expression unevaluated.
So racket uses applicative order because as you said the arguments are evaluated first (unless you use "Lazy Racket" in which case it uses call-by-need aka lazy evaluation, which is like normal-order except each argument is evaluated at most once).