# L11Clos - Closures and Streams cs784(Prasad L11Clos 1...

This preview shows pages 1–9. Sign up to view the full content.

cs784(Prasad) L11Clos 1 Closures and Streams

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
cs784(Prasad) L11Clos 2 Models of Evaluation Substitution-based (define (square  x ) (*  x x )) ((lambda ( x   y     (+ (square  x ) (square  y )))                            (- 5 3)   5 ) = (+ (square 2) (square 5))  = (+ (* 2 2) (* 5 5)) =   (+     4      25) =          29
cs784(Prasad) L11Clos 3 Expression Evaluation Options To evaluate: (operator operand1 operand2 operand3 . ..) Applicative-Order Evaluation ( call by value) evaluate each of the sub-expressions. apply the leftmost result to the rest. Normal-Order Evaluation ( call by name ) apply the leftmost (lambda) sub-expression to the rest and expand. (Argument sub- expressions get evaluated when necessary.)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
cs784(Prasad) L11Clos 4 Models of Evaluation Environment-based ((lambda ( x   y     (+ (square x) (square y)))                            (- 5 3)   5 ) = (+  (square x)   (square y) )    x = 2 , y = 5 = (+  (*  x x )                    x = 2 , y = 5          (*  x x x x )  )                 x x = 5 , y = 5 = (+     4      25) =          29
cs784(Prasad) L11Clos 5 An extended example (define square (lambda (x) (* x x))) (define sum-of-squares      (lambda (x y)            (+ (square x) (square y)))) (define f (lambda (a)     (sum-of-squares (+ a 1) (* a 2))))

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
cs784(Prasad) L11Clos 6 Initial Global Environment
cs784(Prasad) L11Clos 7 Executing (f 5)   and   sum-of-squares

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document