Lazy Evaluation? (Call by Need vs. Value)

The original design for Better Scheme was built around lazy evaluation as embodied in the call by need semantics. It was felt this gave many advantages including more consistency and the ability to manipulate infinite structures. Part of this choice was however based on the mistaken assumption that call by need could be used to replace all forms of macros. However, it is not powerful enough to implement constructs such as let and letrec. In addition, upon trying to implement call by need it was found that it would be very difficult to implement the standard library functions and to interface Better Scheme code to Java or another language. Finally, early attempts at programming in Better Scheme showed the results of lazy evaluation to be unpredictable by human programmers.

Because the issue is being re-thought, what follows is a table of the advantages and disadvantages of the two reasonable calling semantics.

Call by Need (lazy)Call by Value (strict)
Advantages
  • Infinite Lists.
  • Never compute unneeded values.
  • Don't get stuck in infinite recursions if return value not used.
  • Used to easily implement if, and, or.
  • Explanation and implementation of the ',' (evaluation operator).
  • Simple and well understood.
  • Predictable.
  • Easily implemented.
  • Interacts well with other languages.
Disadvantages
  • Confusing to program.
  • Difficult to predict, especially with side effects.
  • Almost impossible to implement.
  • Doesn't link well to other languages.
  • Still requires macros.
  • Doesn't allow infinite lists.
  • May compute unneeded values.
  • Doesn't explain ',' (evaluation operator).
  • More things must be macros.

Resolution

Lazy evaluation has been removed. It caused to many problems, especially if one attempted to use any form of side-effects. In addition, it does not match with my New Vision for Better Scheme. To allow some of the functionality possible with lazy evaluation, all standard list functions will consider a list to be any function which acts as a list. This allows programmers to implement list functions which generate the list values on an as needed basis (it does however require mutability).



jwalker@cs.oberlin.edu