Created
November 3, 2014 21:30
-
-
Save mrfabbri/c075a7233a83fc0c41cb to your computer and use it in GitHub Desktop.
Shadow stream in Racket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Returns a stream that shadows side-effects of the original stream | |
;; when accessed after the first time | |
(define (shadow-stream s) | |
(let ([shadow-next #f]) | |
(thunk (begin | |
(when (not shadow-next) | |
(let ([next (s)]) | |
(set! shadow-next (cons (car next) (shadow-stream (cdr next)))))) | |
(cons (car shadow-next) (cdr shadow-next)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment