95.501 2000

 2  Scheme Introduction


What's in This Set of Notes ?


2.1 Lisp and Scheme


2.2 Expressions


2.3 Naming and Environments


2.4 Evaluating Combinations


2.5 Compound Procedures


Procedure Definitions


2.6 Substitution Model for Procedure Application

  • Think about procedure application
  • Determines "meaning" of procedure application
  • Applicative-Order evaluation (Scheme approach)
    1. evaluate operator and operands
    2. apply the resulting procedure to resulting arguments

    3.  
      (f 5)
      (sum-of-squares (+ 5 1) (* 5 2))
      (+ (square 6) (square 10))
      (+ ( * 6 6 ) (* 10 10))
      (+ 36 10)
      136

       
  • Normal-Order evaluation (expand and reduce)
    1. substitute operand expressions for parameters until reaching primitive operators,
    2. then evaluate

    3.  
      (f 5)
      (sum-of-squares (+ 5 1) (* 5 2))
      (+ (square (+ 5 1)) (square (* 5 2)))
      (+ ( * (+ 5 1) (+ 5 1) ) (*  (* 5 2) (* 5 2)))
      (+ (* 6 6) ( * 10 10))
      (+ 36 10)
      136

       
  • Which evaluation technique is Better?
  • both approaches result in the same answer
  • applicative-order evaluation is more efficient -> avoid multiple evaluations
  • normal-order also has benefits, will see later