急切求值/应用顺序和惰性求值/正常顺序
据我所知,急切评估/应用顺序在应用函数之前评估函数的所有参数,另一方面,惰性评估/正常顺序仅在需要时评估参数。
那么,急切求值和应用顺序这对术语以及惰性求值和正常顺序之间有什么区别>?
谢谢。
As far as I know, eager evaluation/applicative order evaluates all arguments to a function before applying it, on the other hand, lazy evaluation/normal order evaluates the arguments only when needed.
So, what are the differences between the pair of terms eager evaluation and applicative order, and lazy evaluation and normal order?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
惰性求值最多对一个术语求值一次,而正常顺序会按照它出现的次数对其求值。例如,如果您有
f(x) = x+x
并将其称为f(g(42))
则g(42)
code> 在惰性求值或应用顺序下调用一次,但在正常顺序下调用两次。热切求值和应用顺序是同义词,至少在使用《计算机程序的结构和解释》中的应用顺序定义时是如此,这似乎与您的定义相符。 (Wikipedia 定义的应用顺序有点不同,并将其作为热切求值的特殊情况) 。
Lazy evaluation evaluates a term at most once, while normal order would evaluate it as often as it appears. So for example if you have
f(x) = x+x
and you call it asf(g(42))
theng(42)
is called once under lazy evaluation or applicative order, but twice under normal order.Eager evaluation and applicative order are synonymous, at least when using the definition of applicative order found in Structure and Interpretation of Computer Programs, which seems to match yours. (Wikipedia defines applicative order a bit differently and has it as a special case of eager evaluation).
我也在读SICP,我对作者给出的正常顺序的定义很好奇。对我来说,它似乎与惰性评估非常相似,所以我去寻找有关两者的更多信息。
我知道这个问题很久以前就被问过,但我查看了常见问题解答,发现没有提到回答旧问题,所以我想我应该把我在这里找到的内容留下,以便其他人将来可以使用它。
这是我发现的,我倾向于同意这些:
和
http://c2.com/cgi/wiki?LazyEvaluation
http://cs.anu.edu.au/student/comp3610/lectures/Lazy.pdf
I'm reading SICP too, and I've been curious by the definition of normal order given by the authors. It seemed rather similar to Lazy evaluation to me, so I went looking for some more information regarding both.
I know this question was asked a long time ago, but I looked at the FAQ and found no mention of answering old questions, so I thought I'd leave what I've found here so other people could use it in the future.
This is what I've found, and I'm inclined to agree with those:
And
http://c2.com/cgi/wiki?LazyEvaluation
http://cs.anu.edu.au/student/comp3610/lectures/Lazy.pdf
来自 Kevin Sookocheff 的 正常、应用和惰性评估帖子(强调,我的风格改变):
这太长了,无法作为问题下的评论发布,并且用它更新现有答案似乎不合适,因此这个答案。
From Kevin Sookocheff's Normal, Applicative and Lazy Evaluation post (emphases, stylistic changes mine):
This was too long to post as a comment beneath the question, and updating existing answers with it seemed inappropriate, hence this answer.