Scheme¶
Delayed Evaluation and Streams¶
Two new primitives
(delay expr) => promise(force promise) => value
Stream Functions¶
-
(cons-stream a b)~(cons a (delay b)) -
(define head car)- Gets head of stream
-
(tail stream)- Get tail of the stream
-
(stream-section n stream)- Gives the n first elements of the stream
(add-streams s1 s2)- Pairwise addition of the two streams
Example - Fibonacci Stream
1 2 3 4 | |
Rewrite Rules¶
Alpha Rule¶
Formal parameters of a lambda expression can be substituted by other names, which are not used as free names in the body
Legal Conversion
1 | |
Illegal Conversion
1 | |
Beta Rule¶
An application of a function can be substituted by the function body, in which formal parameters are substituted by the corresponding actual parameters
Legal Conversion
1 2 3 | |
Eta Rule¶
A function f, which only passes its parameters on to another function e, can be substituted by e
1 | |
Legal Conversion
1 2 | |
Illegal Conversion
1 | |
Last update:
January 17, 2021