Wednesday, October 20, 2010

Daily, 2010/10/18: call-by-X

One big idea we touched on briefly in class is that identifier binding—which means function application now that we've compiled withs away—is fundamental to several of the design axes we've considered in programming languages.

Clearly, call-by-value and call-by-reference are two different ways to manage binding function parameters during application.  However, both of these, also contrast with lazy evaluation.

Two other names for lazy evaluation are call-by-name and call-by-need.

In call-by-name semantics, binding a parameter just gives a name for the expression supplied to the function (well, the expression closure, anyway).  Any use of the name is replaced by the expression.  That's lazy evaluation without caching.

In call-by-need semantics, the expression bound to a parameter is only evaluated (and subsequently stored and used as a value) if it's needed at some later point.  That's lazy evaluation with caching.

Neither of these corresponds to call-by-reference or call-by-value (although we can think of call-by-value as being like call-by-need except that we artificially "need" the value right away).

Cheers,

Steve

No comments:

Post a Comment