Homework #12


This problem requires Lecture 9 and book section 1.3.

Exercise 1.31, p.37 - (90 minutes)
see help page. The idea of lexical addresses is in interesting one. This problem requires that you use recursion and auxiliary variables to keep track of depth.

Consider the subset of Scheme specified by the BNF rules

<expression> ::= <identifier>
	     ::= (if <expression><expression><expression>)
	     ::= (lambda ({<identifier>}*) <expression>)
	     ::= ({<expression>}+)

Write a procedure lexical-address that takes any expression and returns the expression with every variable reference v replaced by a list (v :d p), as above. If the variable reference v is free, produce the list (v free) instead.

	> (lexical-address '(lambda (a b c)
		      	(if (eqv? b c)
		       	 ((lambda (c)
			   	(cons a c))
			 	a)
				b)))
		(lambda (a b c)
  			(if ((eqv? free) (b : 0 1) (c: 0 2))
    				((lambda (c)
        				((cons free) (a : 1 0) (c : 0 0)))
     					(a : 0 0))
   					 (b : 0 1)))

Get help early!

YOU MUST NAME YOUR FUNCTION lexical-address.


You must log in first before submitting homework assignments.

Instructions on submitting homework is here


Last updated at 10:59 am on Monday, February 02, 2004.