Homework 5 (Due Monday 2/21/2011 at 10:00am)

Submit this assignment via Owl-Space In contrast to the previous assignments, submit each problem in a separate .ss file: 1.ss, 2.ss, 3.ss, and 4.ss (if you do the extra credit problem). Unfortunately, none of the languages supported by DrScheme will allow these files to be combined. The Pretty Big Scheme language allows top-level indentifiers (functions and variables) to be redefined, but it does not support check-expect. All of the student languages--the only ones that support check-expect--prohibit redefinition.

Embed answers that are not program text in a Scheme block comment or block commenting brackets (#| and |#).

Use the Intermediate Student with lambda language.

Given the Scheme structure definitions:

(define-struct sum (left right))
(define-struct prod (left right))
(define-struct diff (left right))
(define-struct quot (left right))

an arith-expr is either:

where n is a Scheme number, and ae1 and ae2 are arith-exprs.

The following 4 exercises involve the data type arith-expr. If you are asked to write a function(s), follow the design recipe: contract, purpose, examples/tests, template instantiation, code, testing (which happens automatically when the examples are given in (check-expect ...) form). Follow the same recipe for any help function that you introduce.

  1.  (40 pts.) Write an evaluator for arithmetic expressions as follows:
  2.  (40 pts.) Extend the definition of <arith-expr>} as follows:
  3.  (20 pts.) An environment is really a finite function (a finite set of ordered pairs). It is finite in the sense that it can be completely defined by a finite table, which is not true of nearly all the primitive and library functions in Scheme (and other programming languages). Even the identity function is not finite. For the purpose of this exercise, we redefine the type environment as (symbol -> option-binding).
  4. Extra Credit  (50 pts.)  Add support for lambda-expressions in your evaluator as follows: