Source §2 Lazy

Source §2 Lazy is a small programming language, designed for the first chapter of the textbook Structure and Interpretation of Computer Programs, JavaScript Adaptation (SICP JS). Instead of the more common evaluation order of applicative order reduction employed by Source §2, the language Source §2 Lazy uses a variant of normal order reduction called lazy evaluation.

What is lazy evaluation?

In most programming languages, the arguments of primitive operations or functions are fully evaluated before the operation or the the function is applied. This is called applicative order reduction. Section 1.1.5 of Structure and Interpretation of Computer Programs, JavaScript Adaptation (SICP JS), introduces an alternative, called normal order reduction. In this scheme, the argument expressions of functions are passed un-evaluated to the function to which they are applied. The function then evaluates these expressions whenever their values are required. If functions do not have any side-effects, there is no need to evaluate such an expression multiple times, as the result is guaranteed to be the same. This observation leads to the variant of normal order reduction, called lazy evaluation. In lazy evaluation, the evaluator remembers the result of evaluating the argument expressions for the first time, and simply retrieves this result whenever it is required again.

What can you do in Source §2 Lazy?

You can use all features of Source §1, but with the added benefit of lazy evaluation. For example, lists in Source §1 Lazy are lazy: They can be infinite, as shown in Section 4.2.3 of Structure and Interpretation of Computer Programs, JavaScript Adaptation (SICP JS).

You want the definitive specs?

For our development team, we are maintaining a definitive description of the language, called the Specification of Source §2 Lazy. Feel free to take a peek!