University of Virginia, Department of Computer Science
CS200: Computer Science, Spring 2002

Notes: Wednesday 23 January 2002
Schedule

Notes and Questions

Scheme Rules of Evaluation

Evaluation Rule 1: Primitives. If the expression is a primitive, it is self-evaluating.

Evaluation Rule 2: Names. If the expression is a name, it evaluates to the value associated with that name.

Evaluation Rule 3: Application. If the expression is an application:
    (a) Evaluate all the subexpressions of the combination (in any order)
    (b) Apply the value of the first subexpression to the values of all the other subexpressions.

Evaluation Rule 4: Special Forms. If the expression is a special form, do something special.

Application Rule 1: Primitives. If the procedure to apply is a primitive, just do it.

Application Rule 2: Compound Procedures. If the procedure is a compound procedure, evaluate the body of the procedure with each formal parameter replaced by the corresponding actual argument expression value.

Backus-Naur Form Scheme Grammar

Expression ::= Primitive
Expression ::= Name
Expression ::= (Expression ExpressionList)
ExpressionList ::=
ExpressionList ::= Expression ExpressionList
Expression ::= (lambda (Parameters) Expression)
Parameters ::=
Parameters ::= Name Parameters
Expression ::= (define Name Expression)

How would the Scheme Rules of Evaluation evaluate
    ((lambda (x y) (+ x y)) 100 (* 10 10)).


(You will need more space for this.)


Evaluation Rule 3a does not say in what order the subexpressions should be evaluated in. For example, we could evaluate them left to right, or right to left, or in any other order. This is like the MIU-system Rule 3 that does not say which occurance of III should be replaced. Does it ever matter in which order the subexpressions of an application are evaluated? (Tough question, but try to think of a Scheme expression where it would make a difference.)






  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 200: Computer Science
David Evans
evans@virginia.edu
Using these Materials