University of Virginia, Department of Computer Science
CS655: Programming Languages, Spring 2001

Manifest: Tuesday 30 January 2001
Assignments
Thursday, 1 February (in class) Problem Set 1

Readings

No new readings assigned. Re-read the parts of Chapter 4 you didn't understand the first time.

Code
Code excerpts from the lecture.

Higher Order Procedures

(define (double-els lis)
  (if (null? lis) 
      lis
      (cons (+ (car lis) (car lis)) (cdr lis))))


(define (map-els f lis)
  (if (null? lis) 
      lis

      (cons ___________________________

	    
	    _____________________________________)))


(define (increment-els lis)

  (map-els _________________________ lis))


(define (???-els lis)
  (map-els 
   (lambda (x) (lambda (y) (+ x y))) 
   lis))


(define (compose f g x) (f (g x)))

(define (composer lis)
  (if (null? lis) 
      
      ___________________________


      _________________________________________________________________))

Mini-Scheme Metacircular Evaluator

Raw text file: meval.scm. You can load this into your Scheme interaction using
(load "/af10/evans/public_html/cs655/manifests/meval.scm").

(define (bind-variable var value env)
  (cons (cons (cons var value) (car env)) (cdr env)))

(define (extend-environment env)
  (cons '() env))

(define (lookup-variable-value var env)
  (if (null? env)
      (error "No binding for " var)
      (if (null? (car env))
	  (lookup-variable-value var (cdr env))
	  (if (eq? var (car (car (car env))))
	      (cdr (car (car env)))
	      (lookup-variable-value 
	       var 
	       (cons (cdr (car env)) (cdr env)))))))

(define (apply proc operand env)
  (if (eq? (car proc) 'primitive)
      ((car (cdr proc)) operand)
      (eval (car (cdr (cdr proc)))
	    (bind-variable (car (car (cdr proc))) 
			   operand (extend-environment env)))))

(define (eval expr env)
  (if (or (number? expr) 
	  (and (list? expr) (eq? (car expr) 'primitive)))
      expr
      (if (symbol? expr) 
	  (lookup-variable-value expr env)
	  (if (and (list? expr) (eq? (car expr) 'lambda))
	      (list 'procedure (car (cdr expr)) (car (cdr (cdr expr))))
	      (apply (eval (car expr) env) 
		     (eval (car (cdr expr)) env) env)))))

The Tao is the One,
From the One come eval and apply;
From these two, creative energy;
From energy, infinitely many things;
The forms of all computation.

All programming embodies eval
And embraces apply,
Through their union
Achieving harmony.

Tao Te Ching, Chapter 42. (Liberally modified and modernized, with no offense meant to Taoists.)


CS 655 University of Virginia
Department of Computer Science
CS 655: Programming Languages
David Evans
evans@virginia.edu