Difference between revisions of "Thunks and Streams Assignment"
| Line 7: | Line 7: | ||
[https://docs.racket-lang.org/reference/procedures.html?q=procedure-arity#%28def._%28%28quote._~23~25kernel%29._procedure-arity%29%29 procedure-arity] | [https://docs.racket-lang.org/reference/procedures.html?q=procedure-arity#%28def._%28%28quote._~23~25kernel%29._procedure-arity%29%29 procedure-arity] | ||
| + | |||
| + | [https://docs.racket-lang.org/reference/pairs.html?q=cons#%28def._%28%28quote._~23~25kernel%29._pair~3f%29%29 pair?] | ||
| + | |||
| + | [https://docs.racket-lang.org/reference/pairs.html?q=cons#%28def._%28%28quote._~23~25kernel%29._cons%29%29 cons] | ||
| + | |||
| + | [https://docs.racket-lang.org/reference/pairs.html?q=cons#%28def._%28%28quote._~23~25kernel%29._car%29%29 car] | ||
| + | |||
| + | [https://docs.racket-lang.org/reference/pairs.html?q=cons#%28def._%28%28quote._~23~25kernel%29._cdr%29%29 cdr] | ||
=Code To Implement= | =Code To Implement= | ||
Revision as of 18:07, 2 July 2019
Code To Use
Code To Implement
Thunk Utilities
define a function thunk? which returns #t if the specified parameter is a thunk, #f otherwise.
define a macro thunk which creates thunk
define a function dethunk which takes a thunk parameter th and returns the result of invoking th.
Stream Utilities
define a function plausible-stream? which returns #t if the specified parameter is a thunk which when invoked returns a pair whose cdr is a thunk, #f otherwise.
WARNING: what could happen if you called plausible-stream? recursively on the cdr?
define a function next-value-from-stream which takes a stream parameter and returns the next value of that stream.
define a function next-stream-from-stream which takes a stream parameter and returns the next stream of that stream.
define a function stream-cons which takes two parameters value and stream-prime. if the specified stream-prime parameter is not a thunk then an error should be raised:
(raise (error "not a thunk" stream-prime))
WARNING: what could happen if you called plausible-stream? on stream-prime?
Stream App
define flip-flop-stream which produces #t #f #t #f #t #f #t #f...