;; Caltech CS 1 Fall 2007
;; Substitution Model Summary
;; Scheme code used in Lecture 2 (10/03/07)
;; mvanier@cs.caltech.edu

;; General rule:
;; To evaluate a Scheme expression:
;;  1. Evaluate its operands
;;  2. Evaluate the operator
;;  3. Apply the operator to the evaluated operands
;;
;; To evaluate a variable:
;;  1. Look up the value associated with the variable 
;;  2. Replace the variable with the value
;;
;; define is a "special form"
;;   e.g. (define X (+ 2 3))
;; We do *not* evaluate X before applying define to X and 3
;; We simply:
;; 1. Evaluate the second argument: the combination (+ 2 3)
;;    -- evaluates to 5 after several steps
;; 2. Make an association between the first argument X
;;    and the value of the second argument.
;;
;; lambda is also a special form:
;; Result of a lambda is always a function (an operator)
;; We do not evaluate its contents:
;;   -- just save them for later.
;;
;; To evaluate a function call:
;; 1. Evaluate the arguments
;; 2. Apply the function to the evaluated arguments
;;
;; To apply a function: 
;; 1. Replace the function argument variables with 
;;    the values given in the call everywhere they occur
;;    (do this for all arguments)
;; 2. Evaluate the resulting expression
;;
;; To evaluate: (define (f x) (+ x 1))
;; 1. Desugar it into lambda form:
;;    e.g. (define f (lambda (x) (+ x 1))
;; 2. Evaluate like any define:
;;    Create an association between the name, f, 
;;     and the function, (lambda (x) (+ x 1))
;;
;; These rules tell you how to evaluate any Scheme expression
;; we've seen so far; that is, how to understand the meaning that 
;; Scheme will assign to the expressions.

