CS 3520 Homework 6   - Due October 11

Exercise 6.1, Adding Recursive Bindings to the Toy Language

Your task: Extend your interpreter from HW5 with a new letrec-like form.

The syntax of the language is extended as follows:
  <expr> = ...                             ;; same as HW5
         | {[<expr>], <expr>}              ;; recursive local binding
To evaluate the expression
{[expr1], expr2}
the environment for evaluating expr2 is created by extending the current environment with a closure. That closure's body is expr1, and the closure's environment starts with a binding for itself. The result of evaluating expr2 in its environment is the result of the entire expression.

In other words, the above expression is analogous to a Scheme expression
(letrec ([F (lambda (x) expr1)])
   expr2)
or, in the book's language,
letrec F = proc(x)expr1
  in expr2
except, of course, that the variables F and x are not named. Instead. lexical numbers are used to access the variable bindings.

Note that a curly brace deepens lexical variable bindings, just like a square bracket.

Implement the new form with the following steps:
  1. Extend the language's grammar with the new expression form, letrec-exp.
  2. Extend the environment implementation to handle recursive bindings:
  3. Update eval-expression to implement the new expression form using extend-env-recursively.


Last update: Tuesday, October 3rd, 2000
mflatt@cs.utah.edu