Homework 4 (Due Monday 9/29/2022 at 11:59pm)

To submit this assignment, simply upload the files in your GitHub repository to you GitHub Classroom repository for this assignment (as you have done for earlier assignments).   In contrast to Assignments 1 and 2 where you could put the programs for all problems in a 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, namely HW04-1.rkt, HW04-2.rkt, HW04-3.rkt, and HW04-4.rkt (if you do the extra credit problem) for problems 1, 2, 3, and 4 (extra credit). Unfortunately, none of the languages supported by DrRacket allow these files to be combined. The Pretty Big Racket language allows top-level identifiers (variable names) to be redefined, but it does not support check-expect. All of the student languages—which are the only ones that support check-expect—prohibit redefinition of identifiers.

Embed any answer text that is not executable 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 number (as defined in Racket), 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 presented using (check-expect ...) ). Follow the same recipe for any help function that you introduce.  You may use any of the library functions shown in class lectures including append.

  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: