Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Shadow stream in Racket
;; 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