-
Notifications
You must be signed in to change notification settings - Fork 14
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement labels and goto #509
Comments
It's only the Currently I see little point in making labels first-class, actually. You can't really do anything with them... Print their name, I guess? Forward |
|
Drive-by comment to note that there's an interesting parallel between (Symbols on there other hand don't have the semantics of "branch target" that labels do.) My best bet is that labels contain/has-a symbol, and expose some of its uniqueness semantics. |
Still not sure. But if we make them OK, we need to account for the fact that parameter defaults can contain arbitrary code.
If you jump straight into the Now, what if |
How, exactly, does In general, we have not even seen the label we are jumping to when we see the (Aaaaugh!) |
I think the ruling must be this: On the other hand, stack unwinding and |
Ok, this SO answer is relevant/interesting. |
I came in here to point out that the problem with Respecting As to |
I came here to mention in passing that, in JavaScript, labels do have lexical scope, as far as I can determine. Specifically, you can do this: function foo() {
label1:
{
console.log("hi");
break label1;
}
label1:
{
console.log("hi");
break label1;
}
label1:
{
console.log("hi");
break label1;
}
} (You can re-use the same label many times in the same function, as long as their scopes don't lexically shadow each other. Even that would be OK, I guess, albeit unnecessarily confusing.) Stating the obvious, though, this lexical scoping works fine as long as we're only dealing with I think that settling on function-level scoping (脿 la JavaScript's |
In a module, of course. 馃槈 (Added to #401.)
The extent of
goto
is an interesting topic. I'm fine with being conservative in a first iteration, meaning never into or out of blocks, even intra-func blocks. (So the above example wouldn't work.)Later, we can loosen it up to Perl 6's theoretical maximum: out of any number of blocks (unrolling the stack as needed) and into any number of blocks, as long as no block needs parameters. (Not sure whether parameters with defaults are OK.) The semantics described also mean that labels don't exactly have lexical scope; instead they are scoped to their surrounding function or mainline, like JavaScript's
var
bindings.Labels can be first-class, and show up lexically as fairly shy instances of
Label
.I make no value judgements as to whether
goto
is a net moral good, or whether it can always be written in better ways. As soon as we are far enough along with a separate runtime, this should be a macro we can write quite easily.(However, if you try to
goto
out of a quasi and into the surrounding macro body, don't expect the compiler to be merciful in its error message.)The text was updated successfully, but these errors were encountered: