WRIGHT STATE UNIVERSITY
Department of Computer Science and Engineering
   CS 7100 Fall 2025                                                                                                                            Prasad

Assignment 3  (For pacing yourself: November 6, 11:59pm) 

1. Interpreter Modification (asg3.rkt) 

Consult EOPL 2nd ed. text. Section 3.5 and Exercise 3.27 on Pages 84-91.

Exercise 3.27: When we build a closure, we have kept the entire environment in the closure. But of course all we need are the bindings for the free variables. Modify the interpreter to use the following definition of closure:

(define closure
(lambda (ids body env)
(let ((freevars (difference (free-vars body) ids)))
(let ((saved-env
(extend-env
freevars
(map (lambda (v) (apply-env env v)) freevars)
(empty-env))
)
)
(lambda (args)
(eval-expression body (extend-env ids args saved-env)))
)
)
))
where difference takes the difference of two sets. This is called the flat closure representation. The environment of such a closure consists of exactly 
one rib comprising its free variables and their values.

That is, modify the interpreter code in myinterp.scm to support statically scoped user-defined procedures with the representation for closure as shown. Note that you need to supply the definition for free-vars and make any other necessary changes to incorporate the new definition of closure.


What to develop?

Create well-tested solution in a file named  asg3.rkt. Make sure that the solution file can be loaded and run in Racket IDE without any modification. In order to better present the changes you made, comment out the code you are modifying rather than deleting it in asg3.rkt. Include test calls and outcomes so as to make it clear that you are exercising all the constructs. 

What to turn in?   
You may turn-in your single runnable Racket file
asg3.rkt on Pilot under Dropbox > Assignment 3.