-
Notifications
You must be signed in to change notification settings - Fork 5
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
General-purpose short-circuit #81
Comments
Great suggestion!
That's correct, this controls whether the outcomes are seen in ascending order ( Maybe I should use the word
At current I don't have a general-purpose short-circuit, though the thought has at least crossed my mind. Currently there are two specific short-circuit mechanisms: First, when Second, the This is done on the pool side rather than the evaluator side; while not a general short-circuit mechanism, this does have some advantages of its own:
The explicit pool syntax would be
(Un?)fortunately, this does steal a good deal of the thunder of the general case. Though there are some cases that don't fall under this, e.g. Neon City Overdrive. The potential benefits seem to come in two aspects:
|
This is probably the most significant factor. It very well could be that so few cases benefit from the complexity (and possible overhead, depending on implementation) of a short circuit like the one I propose that they deserve explicit specialization (e.g., |
Regarding the use of exceptions to signal the shortcut case: I like that approach, although I think it a small tweak would make it more pythonic. The example code uses an exception as a sort of "long-distance return" statement, both signaling the end of iteration and returning the final value in the exception arguments. Contrast that with the Python generator protocol, which returns the final iteration on one pass and then raises Here's an alternate example using that protocol:
This approach has advantages and disadvantages. On the negative side, it means that you get an extra level of fan-out in the traversal, because you'll be signaling one past the end, instead of signaling at the end. On the other hand, this iteration protocol is so common in Python that it may be the cleanest way to implement shortcuts, especially for cases that have an underlying generator, iterator, or sequence, because those are all cases that naturally lend themselves to a terminal StopIteration or IndexError at the one-past-end point. |
Originally posted by @posita in #26 (reply in thread)
# <omitted>
The text was updated successfully, but these errors were encountered: