Homework 4 (Due Monday 10/05/2020 at 11:59pm)

Simply store the files in your turnin SVN repository to submit this program as you did for Assignments 1 and 2.   In contrast to Assignments 1 and 2 where you could put the programs for all problems in the single file (HW01.rkt for Assignment 1 and HW02.rkt for Assignment 2), you must store the solution to each problem in a separate .rkt file: HW04-1.rkt, HW04-2.rkt, HW04-3.rkt, and HW04-4.rkt (if you do the extra credit problem). Unfortunately, none of the languages supported by DrRacket will allow these files to be combined. The Pretty Big Racket 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 DrRacket block comment or block commenting brackets (#| and |#).

Use the Intermediate Student with lambda language.

Given the Racket structure definitions:

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

an ArithExpr is either:

where n is a Racket number, and ae1 and ae2 are ArithExprs.

The following 4 exercises involve the data type ArithExpr. 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 ArithExpr 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 Racket (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 from Problem 2 as follows: