[plt-scheme] srfi-42, values, named let, etc.
In my neverending quest to get a :nested generator for srfi-42 I have
managed to get to the following
(define-generator (:nested stx)
(syntax-case stx ()
[(:nested (var ...) gen ...)
#'(:do (let-values ([(fun-in done-in var ...)
(let/cc ret
(do-ec gen ... (let/cc enter
(call-with-values (lambda () (values enter #f var ...)) ret)))
(let ([var #t] ...)
(call-with-values (lambda () (values #f
#t var ...)) ret)))]))
((fun fun-in)(done done-in)(var var) ...)
(not done)
(let ())
#t
((fun)))]))
This kinda-sorta-almost works, it is good enough for my purposes, but
there is one place that it collapses, and that is in expressions like
(:parallel (:nested <generator>+) <generator>+)
The reason for this is the code expands to something like
(let-values ([(fun done a b)
(let/cc ret
(do-ec <generators>
(let/cc enter (call-with-values (lambda ()
(values enter #f a b)) ret)))
(call-with-values (lambda () (values #f #t #f #f)) ret))])
(let loop ([fun fun][done done][a a][b b])
(if (not done)
(begin
<Do stuff>
(loop (fun))))))
The problems occur with (loop (fun)) where loop is the function
created by the named let, and fun is a function that returns multiple
values. The problem exists when we embed this into the :parallel
generator, which expects the loop function to be called with a list of
parameters, and operates by concatenating the parameter lists.
Unfortunately we did not use a parameter list.
I have a few questions.
Is calling the named let function as I do legal scheme in general, or
is it a feature of PLT scheme (if I stare at it long enough it appears
to be magic).
Is there some way of modifying it so that it plays nice with
:parallel? Alternatively, is there some way of modifying :parallel so
that it plays nice with the above ?