diff --git a/d-.scm b/d-.scm index bbf8a65..0479b88 100644 --- a/d-.scm +++ b/d-.scm @@ -6,7 +6,8 @@ if-not when-not partial - argmin)) + argmin + make-generator)) (define-syntax ~> (syntax-rules () @@ -36,3 +37,15 @@ min)) #f vals)) + +;; Shamelessly ripped from https://wingolog.org/archives/2013/02/25/on-generators +(define (make-generator f) + (define tag (make-prompt-tag)) + (define (thunk) + (f (lambda (val) (abort-to-prompt tag val)))) + (lambda () + (call-with-prompt tag + thunk + (lambda (k value) + (set! thunk k) + value))))