~mc28/labs/evaluators-w-state/micro-scheme.scmand use the "Save Definitions As..." command to save a private copy in your own directory, which you will modify. Use the ``Execute'' button to evaluate all the definitions in that file. This file contains the Micro-Scheme implementation from section 10.3 of the text, along with some necessary definitions from section 10.2 and earlier chapters of the text.
(read-eval-print-loop)in Scheme and then try evaluating various Micro-Scheme expressions in the resulting Micro-Scheme read-eval-print loop. When you are done trying out Micro-Scheme and want to return to real Scheme, you can use the ``Break'' button at the top of the window.
look-up-value, as described in exercises 10.11 and 10.12 on page 299 of the textbook. For 10.11, you could add
null?, so that you can do list processing in Micro-Scheme. For 10.12, you can add anything you've wished Scheme had built in, perhaps
square. Try out Micro-Scheme again, making sure that your new pre-defined names work.
withexpressions to Micro-Scheme. This will involve modifying the definition of
micro-scheme-parsing-p/a-list. You shouldn't need to modify any other existing definitions -- you should just modify
micro-scheme-parsing-p/a-listand add any new definitions you need.
Here are two somewhat tricky
with expressions; think carefully
about what the value of each of them should be, and make sure your
implementation produces those values:
(with x = (+ 2 3) compute (with y = (+ x 4) compute (* x y))) (with x = (+ 2 3) compute (with x = (+ x 4) compute (* x x)))
Be sure to try to test every change to the code you make as soon as
possible. This way, if there is a bug, you'll know exactly where to
look. For this exercise, for example, you first may wish to make a
pattern/action for the
with statement that
allows you to test the pattern matching, before concerning yourself
with how these expressions should actually be turned into ASTs. In
particular, you can temporarily use the following action:
(lambda (variable value-expression body) (display "with expression parsed with variable ") (write variable) (display ", value expression ") (write value-expression) (display ", and body ") (write body) (newline) (make-constant-ast 7))This will of course not behave at all as with expressions should: it will make all with expressions always evaluate to 7. However, this "testing stub" will allow you to see that with expressions are being correctly pattern matched. Once you have checked that, you can replace the action with a real one.
~mc28/labs/evaluators-w-state/mini-additions.scm; copy all the definitions from that file, and paste them at the end of your copy of micro-scheme.scm. Save the modified version of as micro-scheme.scm out as mini-scheme.scm, to make clear what it is now becoming.
make-initial-global-environmentalong the lines of your
look-up-valuefrom the first part of the lab.
make-name-astso the name ASTs use
look-up-value. They should get the global environment from the
read-eval-print-loopso that each time the procedure
loopis invoked, the first thing it does it to set the
mini-scheme.scmthe further additions given in the file
~mc28/labs/evaluators-w-state/explanatory-additions.scm. Because these additions include a new version of the
evaluateprocedure, you should delete or comment out the earlier version, to avoid confusion. At this point, you have what you need to complete the next few steps of the lab before mini-scheme will again be working, with its new explanatory output.
make-application-astas shown on page 312 above the exercise. To facilitate testing, start with the the types of AST that go at the leaves of parse trees (names and constants) and then move up to the other kinds of AST. Test each AST constructor immediately after you've changed it by unparsing the result of parsing an appropriate expression. That is, you can do a test like the following, but with the box replaced by an actual mini-scheme expression:
make-read-eval-print-loop-stateso that the repl-state has room to hold a level as well as a global environment. Add a selector,
get-leveland a mutator,
set-level!, to operate on repl states. Test these operations in isolation, by setting a global environment and a level into the repl-state and then getting them back out. Then put the code into
read-eval-print-loopto initialize the level to 0 before the
loopis entered the first time.
evaluateshould be changed to
evaluate-additional. Change them.
blank-lineinto the procedures generated by
Choose your test cases carefully so that they exercise all lines of code and all cases without overburdening the reader with redundant tests. Explain the reasoning behind why you chose the test cases you did. What problems didn't you test for?
The gradesheet for the project is available in PostScript or PDF format. (If you print a copy out, you can staple it to the front of your project report to save paper.)