Do not use set!
or
set-structure-field!
for
this assignment -- your
code would be unnecessarily complicated.
Your solution file: Make sure a copy of your solutions is on your owlnet account in your class sub-folder comp210/hw-ec1.ss, so that if necessary the labby can open and run your program.
You are NOT required to show the template for your programs (woo-hoo!). However, your functions should still follow the appropriate template. And of course, each function should still have a contract and purpose, and reasonable test cases.
Before you tackle the homework, remind yourself of our General Advice, Advice on Homeworks (in particular: staple and provide questions), and the Grading Guidelines.
In this assignment, you will write Drscheme yourself. Well, more accurately, you'll write the interpreter (the bottom, interactions window).
The fact that you write a Scheme program to interpret scheme is coincidental; you could write this same program in a different language, or you could interepret a different language in scheme (as in one of the challenge labs). We choose to interpret scheme because The Law of Scheme is elegantly small; we choose to write the interpreter in Scheme because using Scheme is easier than most other general-purpose languages.
Note that we do not deal with the problem of parsing: that is, turning a raw sequence of characters into an internal representation of what's meant. (Parsing is a separate problem, addressed in comp314, comp412, and perhaps a later challenge lab.) So this hw begins with the idea that we are provided with some internal representation of scheme expressions (structures); our problem is how to evaluate these expressions.
Do exercises 14.4.1 -- 4 and 17.7.1 -- 4. This is will be scaled to be worth 8 exam-pts. Strive for particularly clean, elegant code, and be sure to have clean data definitions and templates, since all your code follows from there. Include a ~1 paragraph discussion of what it would take to expand your interpreter to write recursive functions (e.g. the factorial function, from early lectures). (Hint: nothing too profound -- just more variations on a theme.)
Note that "evaluate-with-one-def" is a generalization of "evaluate-expression" -- it just evaluates expressions which aren't necessarily numeric.
For an additional 2 exam pts, change your program to allow lambda-values. That is, for 17.7.1, an application involves not the name of a function, but more generally any expression (which had better evaluate to a lambda expression). In 17.7.2, your definitions would use lambda (and would be the "simple" form of define, which just takes in a placeholder). See the Law of Scheme from early notes, for the full rules.
Finally, go back and
allow for both variations of define
(defining simple placeholders,
and the version which implicitly creates a function
as written in 17.7.2 originally).