Homework #22


This problem requires Lecture 18 and book section 3.5.

Syntax Expand - (120 minutes)
This exercise is not from your book. Remember from Lecture 5 that let expressions in Scheme are just syntactic sugar and can be replaced by an application of a lambda expression to operands:

    (let ((a 3)
          (b 4))
      (+ a b))

is equivalent to

    ((lambda (a b) (+ a b)) 3 4)

The same is true in ELL, although the syntax for the languages is different:

    let a = 3
        b = 4
      in +(a,b)

is equivalent to

    (proc(a,b) +(a,b) 3 4)

Write a function called syntax-expand that takes an ELL abstract syntax tree as input and replaces all occurrences of let-exp expressions with the equivalent app-exp expressions whose rators are proc-exp expressions.

I consider your doing and understanding this problem to be very important

Your eval-program function should have syntax-expand inserted to preprocess the syntax tree returned by the parser.

(define eval-program
  (lambda (pgm)
    (cases program pgm
           (a-program (body) (eval-expression (syntax-expand body) (init-env))))))

The simple interpreter with if, let, proc, and app expressions.


You must log in first before submitting homework assignments.

Instructions on submitting homework is here


Last updated at 4:02 pm on Tuesday, June 06, 2006.