what is lazy evaluation?
Scheme’s notion of evaluation
- every expression is evaluated when encountered,where the value will be needed later or not
- results in unnecessary computation
- also some programs will fail when we might expect them not to
example
- (car (cons 1 (/ 1 0)))
fails in Scheme
but why shouldn’t it evaluate to 1?
we don’t care what value is stored in the cdr of the cons cell
exceptions
- special forms can avoid some unnecessary evaluation
- example
(if #t 3 (/ 1 0)) evaluates to 3
-