-
Notifications
You must be signed in to change notification settings - Fork 33
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
break
used as value for detecting broken loops, simpler global ref resolution
#359
base: main
Are you sure you want to change the base?
Conversation
Necessary for expressionization that creates functions
Fixes `var broke` colliding with otherwise declared `broke` variable
One thing to note is that this will prevent a possible alternative
|
Good point. CoffeeScript doesn't allow those, because it's hard to do (can't do it with iife), but that doesn't mean it's not a good idea to support (with exceptions or symbols, as discussed in #202). I wonder if it would be better to use a different identifier like |
I think we can still use |
While I liked What about some meta-like incantation like |
Maybe |
Oh, Another idea that I had was to use labels: :foo for item of list
...
if foo.break ... This feels better "contained" (it's clear which loop you're talking about). But it conflicts if there's a variable That said, I guess |
|
I'm in favor of the idea to allow us to create labels so |
break
expressionSemantics:
break
used as a value (not a statement) turns into a magic variable which is set totrue
/false
according to previous (or not yet assigned/undefined
if used before any loops occured).var
semantics (hoisted to function block), which is important because you need to use it outside the loop. We could imaginelet
semantics in the block containing the loop, but that seems confusing as everything is implicit...Possible Extension
The examples make me wonder whether you'd like to
break with value
(orbreak value
) to override thetrue
value, so that you could actually get and use that value viareturn break
orvalue := break
. This in particular is a neat way to get the iterated item out of the loop even if it's declaredconst
:The question at this point is, should
broke
be initialized tofalse
in the loop (as in this PR currently), or should it be initialized toundefined
to leave room for this feature?Simpler global ref resolution
Previously,
populateRefs
was far more complicated and made some assumptions about adjacent refs with the same name being able to use the same name. But this messed up when the ref was used both inside and outside a loop and had a conflict only outside the loop.Eventually we should do something smarter, perhaps similar to
jashkenas/coffeescript#5398, to only add numbers as necessary according to scoping (but it's trickier here because of refs declared both
var
andlet
at varying block levels).