This assignment calls for two modifications to your homework 3. For full credit, do both; for partial credit, you can do either one.
Modify your interpreter from Homework 3 part 1 (not the “lazy evaluation” version -- mutation and laziness don't play nicely together!) to implement mutable boxes (as in Chapter 13 of the PLAI book). The input syntax should have four new constructs:
{newbox expr}
, which evaluates the expression
and creates a box whose value is that number. If the expression doesn't
evaluate to a number, it should produce a type error message, just as if
you tried to square root a string.{openbox expr}
, which retrieves the current
value in the box specified by the expression (if it is a box --
otherwise it should produce a type error message); {setbox expr expr}
, which changes
the value in the box specified by the first expression to the number
specified by the second expression. If the first expression doesn't
evaluate to a box, or the second to a number, it should produce a type
error message. The return value of the setbox
expression
should be the number.{seqn expr expr}
(or, if you prefer,
you can make seqn
work on an arbitrary list of expressions).
Evaluates each of the exprs in order, discarding their values
but returning the value of the last one.Modify your interpreter from Homework 3 part 1 to implement mutable variables (as in Chapter 14 of the PLAI book). The input syntax should have two new constructs:
{set varname expr}
, which evaluates
the expression and changes the named variable to have that value. If
the named variable isn't already defined in the current scope, it should
produce an error message. If the expression doesn't evaluate to a number,
it should produce an error message.{seqn expr expr}
(or, if you prefer,
you can make seqn
work on an arbitrary list of expressions).
Evaluates each of the exprs in order, discarding their values
but returning the value of the last one.You are encouraged to do this in teams of two, both students working together on all parts of the assignment; if you do this, turn in one homework with both names on it. I would prefer that you switch partners from one homework to the next, so you get more experience working with different people and so that I have an easier time computing a grade :-)