; Start this script with `csi -:D` to observe heap resizing (use lazy-seq) ; Remove this when in lazy-seq {{{ (define (lazy-reductions kons knil . streams) (letrec ((s (lazy-seq (cons knil (apply lazy-map kons s streams))))) s)) ; (define (lazy-reductions kons init seq) ; (if (lazy-null? seq) ; lazy-null ; (lazy-seq ; (let ((next (kons (lazy-head seq) init))) ; (cons next (lazy-reductions kons next (lazy-tail seq))))))) ; }}} (define (time-stream) (define last (current-milliseconds)) (lazy-seq (cons 0 (lazy-repeatedly (lambda () (let* ((now (current-milliseconds)) (dt (- now last))) (set! last now) dt)))))) (define (make-clock time) (lazy-reductions + 0 time)) (define (render coords) (void coords)) (define (complex-stream time) (lazy-map (cut * 2 <>) (make-clock time))) ; This seems to leak: (lazy-each render (complex-stream (time-stream))) ; This doesn't: #;(lazy-each render (lazy-map (cut * 2 <>) (make-clock (time-stream))))