Lecture 4 - Page 18 : 27
Programming Paradigms
Evaluation Order and Infinite Lists
* Referential Transparency
Referential transparency
An illustration of referential transparency
* Introduction to Evaluation Order
Arbitrary evaluation order - with some limits
Infinite evaluations and error evaluations
Infinite evaluations and error evaluations - clarification
* Rewrite rules, reduction, and normal forms
Rewrite rules
The alpha rewrite rule
The beta rewrite rule
The eta rewrite rule
Normal forms
The ordering of reductions
An example of normal versus applicative evaluation
Theoretical results
Practical implications
Conditionals and sequential boolean operators
Lazy evaluation
* Delayed evaluation and infinite lists in Scheme
Delayed evaluation in Scheme
Examples of delayed evaluation
Infinite lists in Scheme: Streams
Example streams
Stream example: The Sieve of Eratosthenes
Applications of The sieve of Eratosthenes
Exercises
Conditionals and sequential boolean operators
There are functional language constructs - special forms - for which applicative order reduction would not make sense
(if b x y)
Depending on the value of
b
, either
x
or
y
are evaluated
It would often be harmful to evaluate both
x
and
y
before the selection
(define (fak n) (if (= n 0) 1 (* n (fak (- n 1)))))
(and x y)
and
evaluates its parameters from left to right
In case
x
is false, there is no need to evaluate
y
Often, it would be harmful to evaluate
y
(and (not (= y 0)) (even? (quotient x y)))