-
Notifications
You must be signed in to change notification settings - Fork 2k
break/continue make all list comprehensions [] #1669
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
Comments
related: satyr/coco#79 |
If you Ruby has implicit returns... and a CS generally returns an empty array instead:
So it seems fairly consistent. That said, I didn't expect this:
|
I think that last example is actually expected.
... I'm afraid that there's no bones about it --
|
I guess you could call it consistent, but not very useful. Wouldn't the rule "implicit returns give you the value of the last non-control expression" be more useful, since
to give me At any rate, surely it's inconsistent that
gives you
gives you |
Yep. |
So it sounds like we're agreed that Coco's approach would be an improvement here. Want to make $10, @satyr? https://github.com/jashkenas/coffee-script/wiki/Bug-Bounties |
Are we saying that with full understanding of my approach? The notable difference is:
|
Right, no, we don't want that. I was referring to the example in the issue you linked to:
ought to show |
Which requires recursive application of |
Surely there must be some other way to get the loop to compile to
rather than the current
? |
Making Are you grokking how exactly the current behavior is achieved? |
No, I prefer to stay away from implementation details, and just look at behavior. I get that, in a list comprehension,
compiles to
and more complex expressions like
compile to
So conditional control expressions like
That won't work with the way
So, I get that this would be a fairly major implementation change. But if someone figured out a way to solve it, while preserving the current behavior of nested list comprehensions, the CoffeeScripters of the world would thank them. |
So you want:
to become
but:
to become
Correct? |
No, the current behavior of
should remain the same. But
should become
|
That doesn't make sense to me. Can you explain the algorithm in detail? |
Rather than having potentially several
might compile to
|
The algorithm in question is for determining that normal-ness. Which of below are normal?
And what about loops that contain above?
|
The first two are normal. Any conditional (be it Loops that contain their own |
Can you clarify--the first two also seem conditional to me. |
Typo—I meant "any conditional involving |
"... as the last expression of one of its branches," right? Consider:
|
I guess I'm ready to hunt, as long as @jashkenas sees the above instruction reasonable. |
Yep, Trevor's laying out of the rules sounds just about perfect. |
Right, so let's do a more complex example to get to the heart of this:
Clearly, if
Does
Same question. I'd argue that in both cases, the ideal behavior is for
would have to change, so that either So let's say "no, |
|
Right, I was just talking about my intuition. Even Ruby doesn't go that far, though:
|
Eh, so what, still undecided? Would
become
or
? |
I think:
... with the idea that |
Exactly. If a |
So whether to push |
I'm sorry -- I misunderstood, and didn't read closely enough. (under deadline here -- really can't pitch in much tonight).
... is correct. |
Uh, auto-close misfired. Anyway, does that look ok? |
Looks great -- nicely done. |
Has the whole notion of _results being returned at all been put up to serious debate before? It seems to open up a can of worms, and it's a particularly hard thing to sell to CS skeptics, mainly in terms of readability of the generated JS code. Do people take advantage of this feature in real production code? Why does CS return an array where Ruby returns the loop var (and Python/JS return nothing)? |
As to the commit—well done, satyr! Bounty closed. |
Keep'em coming. =D |
The code
compiles as if it were a list comprehension—except that
_results
is never modified:As a result,
func
will always return[]
. Same thing if you substitutecontinue
instead ofbreak
.If you make it
return if condition
, you get no signs of a list comprehension whatsoever, which I find a little disappointing, but at least internally consistent.The text was updated successfully, but these errors were encountered: