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 them.
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 better.
2) Function.gen_active
function g = gen(); gen_active(g) ==> -1 (Function.NOT_STARTED) g() gen_active(g) ==> 1 (Function.ACTIVE) g() 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 generators.
Opinions?
ChrisA
pike-devel@lists.lysator.liu.se