Add generator function

This commit is contained in:
Dane Johnson 2024-10-29 11:41:50 -05:00
parent 8bac998a25
commit 779bc50a77

15
d-.scm
View File

@ -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))))