After a week or 2 of struggling, IronScheme is slowly but surely getting CPS support that will enable full first-class continuations (iow, the can be re-invoked multiple times).
Here is a little teaser:
> (+ 8 (call/cc (case-lambda [(c) (set! plus8 c) (c 5)]))) 13 > (plus8 3) 11
Currently, this executes from the REPL without issues, but there remains a lot of problem areas that still need to be addressed.
Also note, with this version the entire Scheme source gets converted to CPS, and results in a bootfile roughly 2,5 times the previous size. Not sure about performance currently.
Now I need to figure out how to handle a CPS compatible version of letrec/letrec*. Redefining map not to use letrec, allows the following to work:
> (call/cc (lambda (outer) (map (lambda (x) (call/cc (lambda (inner) (set! next inner) (outer x)))) '(1 2 3)))) 1 > (next values) 2 > (next values) 3 > (next values) ( ... garbage ... )
It appears letrec/letrec* is not a problem, but rather values/call-with-values, but that should be trivial to fix 🙂
Appears to be not so trivial after all! 😐
Damn you Confucious! Was using the wrong identity function to pass as a continuation! All working now 🙂