Skip to content

Instantly share code, notes, and snippets.

@LFY
Created October 8, 2011 20:11
Show Gist options
  • Save LFY/1272805 to your computer and use it in GitHub Desktop.
Save LFY/1272805 to your computer and use it in GitHub Desktop.
Scheme generators
(library (generators)
(export
yield->
next-<
begin-<
)
(import (rnrs)
(delimcc-simple-ikarus)
)
(define (next-< stream)
(let*
([val-cont (reset ((cdr stream) 'End))])
(cond [(eq? 'End val-cont) 'End]
[else (let*
([val (car val-cont)]
[cont (cdr val-cont)])
(cons val cont))])))
(define (begin-< stream)
(let* ([start-val-cont (reset (stream))])
start-val-cont))
(define (yield-> val)
(shift k (cons val k)))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment