sicp.io
4.1.4 · Derived syntax

Rewrite new syntax into a rule the evaluator already knows.

A let expression can be translated into a lambda application, keeping the evaluator core smaller while preserving the binding behavior.

Guiding question

What must remain unchanged when let is rewritten as a lambda application?

  • Separate surface syntax from evaluator core forms
  • Collect binding names as lambda parameters
  • Collect binding expressions as application operands
  • Evaluate the transformed expression in the original environment

The transformer takes the binding names from let and places them in a lambda parameter list. It puts the let body in that lambda and places the binding expressions after the lambda as application operands.

The evaluator does not need a second implementation of local binding. Its let case rewrites the expression and sends the result back through the ordinary lambda and application cases in the same environment.

SICP code377 of 1,048,576 UTF-8 bytes
Examples
Result
Output
Value
Diagnostic
Execution trace0 / 0 events
    Programs run in the browser with their result and execution trace.
    Expected result

    The first program returns ((lambda (x y) (+ x y)) 10 32). The second returns 42.

    Trace focus

    In the second run, find the let dispatch and the transformer calls before the lambda is created. The later application extends the environment with x and y, then evaluates the original body.

    Try it yourself

    Change the program and compare the result.

    Add a z binding with value 8 and change the body to (+ (+ x y) z). Predict both the transformed expression and its value.

    Show hint

    The parameter and operand lists grow in the same order. The body remains one expression inside the lambda.

    Complete this lesson

    0 of 23 lessons complete in this chapter0%