Solution to the sixth homework assignment.

This solutions builds on the <call-language>. Here are some comments about how this solution has been structured.
(define <if-language>
  (class ()
    (base <call-language>)
    (base-inst-vars test-clauses initial-environment <primitive>)
    (base-methods (base-parse parse)) 
    (base-init)                       
    (before-inst-var-init
      (set! test-clauses
	(append
	  '(((minus -3) 3)
	    ((if (null emptylist)
	      (cons 1 emptylist)
	      (cons 0 emptylist)) (1))
	    ((if (null (cons 5 emptylist))
	      (cons 1 emptylist)
	      (cons 0 emptylist)) (0)))
	  test-clauses))
      (set! initial-environment
	  (<extended-environment> initial-environment
	    '(emptylist minus cons car cdr list equal zero greater less null)
	    (cons
	      '()
	      (map <primitive>
		(list
		  (lambda (n) (* -1 n))
		  cons
		  car
		  cdr
		  list
		  (lambda (a b) (if (= a b) 1 0))
		  (lambda (a) (if (zero? a) 1 0))
		  (lambda (a b) (if (> a b) 1 0))
		  (lambda (a b) (if (< a b) 1 0))
		  (lambda (a) (if (null? a) 1 0))))))))
      (inst-vars
	(<if>
	  (class (test-exp then-exp else-exp)
	  (base <syntax>)
	  (inst-vars test-exp then-exp else-exp)
	  (methods
	    (eval
	      (method ()
		(let ((test-result (eval test-exp)))
		  (if (not (zero? test-result)) ; true-value? is hard
		                                ; coded here.
		    (eval then-exp)
		    (eval else-exp)))))
	    (unparse
	      (method ()
		(list
		  'if
		  (unparse test-exp)
		  (unparse then-exp)
		  (unparse else-exp))))))))
    (methods
      (name
	(method () 'if))
      (parse
	(method (datum)
	  (form-case datum
	    (if (test-exp then-exp else-exp)
	      (<if>
		(parse this test-exp)
		(parse this then-exp)
		(parse this else-exp)))
	    (else (base-parse this datum))))))))



See here for a solution that uses the new syntax.

Vikram Subramaniam, 1995

vsubrama@cs.indiana.edu