set!

Now that we have let-one working using environments, let's fill in the rest of the features we already had working. Most special forms like begin don't need to change at all. Ones like set! take a bit more work.

Here is my previous implementation of set!:

It evaluates the body, then assigns that value to the variable name in the environment. Now that we have nested bindings we have to do things differently. We have to find the binding for the variable in the environment and update the value. The rule is that set! will affect the same binding that references to the variable would read.

Write a function update that takes an environment, variable name, and value as input. It should update the correct binding in the environment to the new value. Don't worry about undefined variables right now.

1:1



Prev Next