C311 Spring 1997 -- Programming Languages

Assignment 2: Static Properties

Due Tuesday, February 4, 11:59P

  1. EOPL Exercise 2.3.1, bound-vars procedure

    > (bound-vars '((lambda (x) x) y))
    (x)
    > (bound-vars '((lambda (x) x) x))
    (x)
    > (bound-vars '((lambda (x) x)(lambda (x) x)))
    (x)
    > (bound-vars '(lambda (x) (y (lambda (y) (y x)))))
    (x y)		; or perhaps (y x)
    	  
  2. EOPL Exercise 2.3.2, bound? procedure

    > (bound? 'x '(lambda (x) x))               
    #t
    > (bound? 'y '(lambda (x) y))               
    #f
    > (bound? 'x '((lambda (x) x) x))           
    #t
    > (bound? 'x '((lambda (y) x) x))           
    #f
    > (bound? 'x '((lambda (x) y) y))           
    #t
    > (bound? 'x '((lambda (x) y) (lambda (y) x))) 
    #t
    > (bound? 'x '(lambda (x) (lambda (y) x)))  
    #t
    > (bound? 'x '(((lambda (x) y) (lambda (y) x)) (lambda (x) x))) 
    #t
    	  
  3. EOPL Exercise 2.3.10

    For variable references v that are free in the expression, replace the variable reference with the list (v : free).

    > (lexical-address 'a)
    (a : free)
    
    > (lexical-address '(+ a b))
    ((+ : free) (a : free) (b : free))
    
    > (lexical-address '(lambda (a b c)
    		     (if (eq? b c)
    		       ((lambda (c) (cons a c)) a) b)))
    (lambda (a b c)
      (if ((eq? : free) (b : 0 1) (c : 0 2))
          ((lambda (c)
             ((cons : free) (a : 1 0) (c : 0 0))) (a : 0 0))
          (b : 0 1)))
    
    > (lexical-address
       '(lambda (a b c)
          (lambda (d e)
            (lambda ()
              (+ a b c d e f)))))
    (lambda (a b c)
      (lambda (d e)
        (lambda ()
          ((+ : free)
           (a : 2 0)
           (b : 2 1)
           (c : 2 2)
           (d : 1 0)
           (e : 1 1)
           (f : free)))))
    	  
Try to find linear-time algorithms for these procedures. Hint: for each procedure, define an auxiliary procedure that takes an extra argument, which records information on the nature of lexically enclosing bindings.

Submission

Write your answers to the exercises in a file (following the indentation rules), and send that file to

c311@lakshmi.cs.indiana.edu
with the subject line
handin 2
Assuming you've saved your homework in the file ``two.ss'' in the current directory, one way to submit is with the command:
Mail -s "handin 2" c311@lakshmi.cs.indiana.edu < two.ss


Chris Haynes / chaynes@indiana.edu
Last modified: Mon Jan 27 10:15:55 EST