romach
4/15/2017 - 2:59 PM

Evaluation types

Evaluation types

Example procedures

(define (square x) (* x x))

(define (sum-of-squares x y) 
(+ (square x) (square y)))

(define (f a)
(sum-of-squares (+ a 1) (* a 2)))

Applicative-order evaluation

  1. evaluate operator and operands

  2. use procedures with arguments (1)

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

normal-order evaluation

  1. get expression with simple operations

  2. execute expression

(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 100)
136