On Wed, Oct 20, 2021 at 8:44 PM Henrik Grubbström (Lysator) @ Pike (-) developers forum 10353@lyskom.lysator.liu.se wrote:
Not quite correct; normal ones are 0..USHRT_MAX-1 and builtin functions are USHRT_MAX. The subtype is used to select the function entry in the function table for the object.
Ahh gotcha.
AFAIR the generator function gets the suffix "\0generator" appended to its function name, but I'm uncertain whether this is visible at the Pike code level.
It technically is, if you sprintf("%O", f), but that seems a hacky way to recognize generator state functions. It also doesn't recognize generator functions themselves, although that's less important.
There may also be a difference in the value returned by _typeof().
True in a sense, when looking at a specific generator and its state function, but I don't think this can be used to directly recognize them:
fibonacci: /main()->fibonacci function( : function(void | mixed, void | function(void | mixed ... : void) : int | zero)) fib: /main()->fibonacci\u0000generator function(void | mixed, void | function(void | mixed ... : void) : int | zero)
The use-case is an asynchronous function handler. I've started to write it up here:
https://rosuav.github.io/StilleBot/Asynchronicity#asynchronous-functions-wit...
The spawn_task callable needs to be able to recognize a Concurrent.Future or a generator state function as things to await, and anything else as things to return.
If I could ask for the moon here, I'd also really love to be able to know when a state function has finished, other than calling it again and getting undefined back. That would allow a simple check after getting a value to determine whether the value was yielded or returned: if the state function is now finished, then it was returned, otherwise it was yielded (and we should go back and do more stuff later). At the moment, I have to assume that there's still more to do, and then if I ever get an undefined, I assume that the function is finished. That could conceal bugs.
I've been tinkering with trying to create a Function.function_type() function, but so far, it's looking like most of the information is handled at compilation time only.
ChrisA