-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Co-routines #1342
Comments
|
And with varargs (see #1341):
Ahh, we need a way determine the number of varargs arguments; here I used |
So, I really like the idea of Basically, a A A A This would mean there's no need to have |
Another thing, in Icon one can pass new values to co-routines, which values are then available via a special keyword. That would work for jq, though it'd be a bit weird since it would like the OTOH, We could even create threads to run co-routines in the background, and have a builtin that takes an arbitrary number of handles and returns the name/index of one that is ready for I/O, and this could be the basis for async I/O support in jq. Varargs would absolutely be a requirement here. Ultimately, the nice thing about |
Actually, there should be a single operator / syntax for creating co-routines. Co-routines should access inputs passed on each invocation via This will be most similar to... Icon! |
And there should be a |
Possible syntax:
This allows a function to decide to make co-routines out of some of its arguments. The co-routines look like and are functions. When a function exits its frame, it cleans up the co-routines. |
One interesting thing will be handling tail calls: a tail call from a function frame that has co-routines cannot be made a proper tail call without first cleaning up the co-routines. The way I envision this is to have a stack of { There would have to be a new instruction for making a co-routine. It would create a |
An alternative syntax could be |
I really wish I could start testing the coroutines. I actually have and have studied the Icon book. It's obviously out of print, but is available to download! In fact I reread all the old Icon and SNOBOL books and articles in order to learn to program with jq ;-) |
@fadado :] Yes, I have a soft spot for Icon. I do wish it had closures. I also wish it still compiled to C, and preferably C with GCC extensions like local functions and computed gotos. Examining the old Icon compiler output was a fun way to learn what continuation passing style (CPS) is and how it works. Regarding co-routines, I guess an implementation plan would look like this:
|
The good news is that I am getting confident about both, the design and the syntax. |
Also, I want this as much as you, @fadado. |
It'd be nice to be able to write:
or even better:
This is somewhat inspired by Icon's co-routines. In Icon one can also pass new inputs to co-routines, and even refresh (restart) them, but for jq I think passing a new input to a co-routine would be the same as restarting it. Restarting a co-routine could be
restart(@name)
, which will get whatever.
is passed in as its new input.The text was updated successfully, but these errors were encountered: