DrRacket 解释器是否使用基于 SICP 练习 1.5 的正态顺序评估?

发布于 2024-10-07 09:25:50 字数 387 浏览 0 评论 0原文

人们必须根据以下值做出决定:

(测试 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叶落知秋 2024-10-14 09:25:50

这显示了正常顺序求值,因为操作数在替换参数之前先求值

。实际上,您的理解方式是错误的。应用顺序是首先计算操作数的顺序。正常顺序是指将参数代入未计算的表达式中。

因此,球拍使用应用顺序,因为正如您所说,参数首先被评估(除非您使用“Lazy Racket”,在这种情况下,它使用按需调用又名惰性评估,这就像正常顺序,除了每个参数最多评估一次)。

This shows normal-order evaluation, because the operands are evaluated before being substituted for parameters

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文