[racket] stream-cons from racket/stream isn't lazy
To clarify the last point. Say each seq has a method to create an
equivalent memoized seq, or return itself if memoization is not needed
(e.g. in-range). Memoized seq returns a memoizing iterator, that first
goes over previously calculated values, then starts storing newly
calculated values in seq as it calculates them. Interface for this is
a function stream-memoize :: seq -> seq. So
(let ([s2 (stream-map func s)])
(for ([i s2]) ...)
(for ([i s2]) ...))
calculates all values twice (but does not use additional memory), but
(let ([s2 (stream-memoize (stream-map func s))])
(for ([i s2]) ...)
(for ([i s2]) ...))
only calculates values once.
Eugene