Interpreting let-one

Now that you have your lookup function written we can update the Scheem interpeter to use it for variable references. We'll start with a minimal interpreter that can just do numbers, +, and variable references, then add support for let-one.

Remember that (let-one _var _expr _body) works by evaluating _expr, binding the result to _var, then using that new environment to evaluate _body.

Write a version of evalScheem that works with numbers, +, variable references, and let-one, using the new environment data structure. You can assume lookup is already defined.


The syntax can get a little tricky here. I started defining my bindings like this:

var bnds = { };
bnds[expr[1]] = ...

Then I created a new environment with those bindings:

var newenv = { bindings: bnds, outer: ... };

Then I used that newenv environment to evaluate the body.

Prev Next