Closed masak closed 8 years ago
wait, what? why should it return from the macro? if I want to quasi a return, what's the issue?
why should it return from the macro? if I want to quasi a return, what's the issue?
return
lexically binds to its surrounding routine. Subs and macros are routines. Ifs and whiles and immediate blocks and BEGIN
blocks and quasis
are blocks, but they're not routines. As such, they are "transparent" to return
.
If you want to return from a routine in your compiling context (the mainline), then we could support that, but that should probably be spelled COMPILING::return
.
please no. That's mixing exactly the same level of things as my $a = 4; quasi { $a }
, and it's only more confusing to everyone.
please no. That's mixing exactly the same level of things as
my $a = 4; quasi { $a }
, and it's only more confusing to everyone.
I'll be honest and say that I don't think that bit is going to change unless a significantly more attractive and consistent counter-proposal materializes.
proposal: leave the separated levels separated. don't eval quasi-level code at the macro-level (or opposite)
proposal: leave the separated levels separated. don't eval quasi-level code at the macro-level (or opposite)
There's only three possible outer contexts it makes sense for a quasi
block to have:
The first one is the current proposed semantics, for Perl 6 and for 007. Among the three, I do find it the most useful and least confusing one, in that it works like all other blocks/lookup in the language.
The second one is easier to implement, but means that un-hygiene is the default. I'm all for allowing un-hygiene, but I don't think it should be the default.
The third one I haven't considered, but I don't really see an advantage to it. It feels strictly less powerful than either of the other two.
I confess to not relating well to your phrase "don't eval quasi-level code at the macro-level". (To me it's just scoping as usual.) Maybe that means I misunderstood; if so, please feel free to clarify.
I don't think return
counts as "un-hygiene", FWIW, Hygiene is largely regarded as only being about name clashes. if you want to prevent return
s from being inserted as unhygienic, do you also want to prevent throws?
I think implicit in my points is that in Perl 6, return
is lexical. (Or, more exactly, lexotic.)
In other words, the relation between return
and its surrounding sub
is not all that different to the relation between variable use and that variable's declaration. They're both predictable because they're static, dependent only on lexical program structure.
To answer your semi-hypothetical question, die
semantics does not fit into this thinking, because the "declare" end of that is an in-general-unknowable catch
clause up the CALLER
chain. In other words, die
sets up a dynamic communication with its catch
where return
sets up a lexical one with its sub
.
Putting it a third way, I consider this issue to be a special case of #47.
This has a nice error message:
But look at this, that's internals leaking through:
Eew.
In fact, this is simply because the "Attempt..." error is a parse error, and that second
return
is inside of a macro... hm. We do have a similar throw in Runtime.pm, but maybe it's not triggered anymore.But the real problem is this:
See? It returns from
foo()
, a routine it has no business returning from. Very unhygienic. Clearly it should be returning from the macrom
, and we should be getting an error very much like this:In short,
return
should bind lexically to its surrounding routine, even if it's in a quasi. Just like variables do.