applicative-order/call-by-value and normal-order/call-by-name differences

巧了我就是萌 提交于 2019-12-06 16:03:57

Applicative order (without taking into account the order of evaluation ,which in scheme is undefined) would be equivalent to cbv. All arguments of a function call are fully evaluated before entering the functions body. This is the example given in SICP

(define (try a b)
  (if (= a 0) 1 b))

If you define the function, and call it with these arguments:

(try 0 (/ 1 0))

When using applicative order evaluation (default in scheme) this will produce and error. It will evaluate (/ 1 0) before entering the body. While with normal order evaluation, this would return 1. The arguments will be passed without evaluation to the functions body and (/ 1 0) will never be evaluated because (= a 1) is true, avoiding the error.

In the article you link to, they are talking about Lambda Calculus when they mention Applicative and Normal order evaluation. In this article wiki It is explained more clearly I think. Reduced means applying reduction rules to the expression. (also in the link).

α-conversion: changing bound variables (alpha);

β-reduction: applying functions to their arguments (beta);

Normal order:

The leftmost, outermost redex is always reduced first. That is, whenever possible the arguments are substituted into the body of an abstraction before the arguments are reduced.

Call-by-name

As normal order, but no reductions are performed inside abstractions. For example λx.(λx.x)x is in normal form according to this strategy, although it contains the redex (λx.x)x.

A normal form is an equivalent expression that cannot be reduced any further under the rules imposed by the form

In the same article, they say about call-by-value

Only the outermost redexes are reduced: a redex is reduced only when its right hand side has reduced to a value (variable or lambda abstraction).

And Applicative order:

The leftmost, innermost redex is always reduced first. Intuitively this means a function's arguments are always reduced before the function itself.

You can read the article I linked for more information about lambda-calculus. Also Programming Language Foundations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!