Skip to end of metadata
Go to start of metadata

it would be great if the compiler provided some support for functions that can pause their execution returning some object that can be used to resume execution at a later time. the uses of such functionality are manifold, of particular interest there is a set of macros that basically implement a clojure -> clojure compiler in core.async that transform clojure code in to a form that can execute this way.


proposed syntax:


the name for the tag (:resumable) may need some thinking on, but I think the usage (parallels :once) is pretty uncontroversial, and a new special form 'yield' would be introduced.


yield takes one argument and returns one argument, the yielded value would be returned to the caller as part of the package of state required to resume execution, yield's return value would be provided by whatever initiates the resumption of the computation.


proposed interface for values representing resumable function calls:


a resumable function would always return a Resumable, a Resumable can be resumed with some value with the resume method, getValue will return the last yielded value until the function completes, at which point it will return the functions return value, once a Resumable transitions to a Completed state it is an error to call resume.

the compiler will generate a class that implements Resumable for all resumable functions that includes fields for all the locals used in the body of the function