Add generator function
This commit is contained in:
parent
8bac998a25
commit
779bc50a77
15
d-.scm
15
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))))
|
||||
|
Loading…
Reference in New Issue
Block a user