Skip to content

Instantly share code, notes, and snippets.

@rileylev
Created August 22, 2019 00:40
Show Gist options
  • Save rileylev/31264dabdf9935a42255216abb6b6ea3 to your computer and use it in GitHub Desktop.
Save rileylev/31264dabdf9935a42255216abb6b6ea3 to your computer and use it in GitHub Desktop.
using prompts (delimited continuations) to build generators
(define yield (prompt-tag))
(define (count-helper)
(let loop ((n 0))
(abort-to-prompt yield n)
(loop (1+ n))))
(define this-step count-helper)
(define (count)
(call-with-prompt yield
this-step
(lambda (next-step result)
(set! this-step next-step!)
result)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment