Proposal: Built-ins for generators

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Proposal: Built-ins for generators

Chris Angelico
A generator function will, when called, return a generator state
function. (Are there better terms for these?) It'd be extremely
helpful to have a couple of built-in functions to give some info about

1) generatorp

continue int gen() {continue return 1; return 2;}

generatorp(gen) ==> 1
generatorp(gen()) ==> 2

Alternatively, since these are both functions, functionp could return
1 for regular functions, 2 for continue functions, and 3 for
continuation functions, but I think a separate generatorp function is

2) Function.gen_active

function g = gen();
gen_active(g) ==> -1 (Function.NOT_STARTED)
gen_active(g) ==> 1 (Function.ACTIVE)
gen_active(g) ==> 0 (Function.ENDED)

Once a generator state function is in the ENDED state, calling it will
always return UNDEFINED. Having this function available will allow the
state to be recognized without an additional call.

Open to discussion/bikeshedding on the details, but these functions
would be extremely helpful in building an asynchronous system using