develooper Front page | perl.perl5.porters | Postings from November 2016

Re: are lexical subs supposed to override keywords?

Thread Previous | Thread Next
From:
Aristotle Pagaltzis
Date:
November 28, 2016 00:01
Subject:
Re: are lexical subs supposed to override keywords?
Message ID:
20161128000143.GA75788@plasmasturm.org
* Father Chrysostomos <sprout@cpan.org> [2016-11-14 18:12]:
> On Nov 14, 2016, at 1:29 AM, Dave Mitchell <davem@iabyn.com> wrote:
> > It surprised me that perl keywords are overridden by lexical sub
> > names. Is this intentional? I couldn't find anything in perlsub
> > about it.
> >
> >    my sub for { print "in lex sub (@_) \n" }
> >    for (1,2);
> >
> > outputs
> >
> >    in lex sub (1 2)
>
> That is wholly intentional. It is similar to how a lexical @INC
> overrides the global @INC. The core keywords could all be thought of
> as being in a namespace that gets searched by default before the
> current package. Lexical symbols always take precedence over other
> namespaces.

How is it at all similar? If you take away the `my` in that example, the
code will not compile at all, and there is no way to make it. There is
no way of doing within package scope what lexical subs are here allowed
to do within lexical scope.

I don’t know if that’s good or bad. Knee-jerk reaction says it must be
bad because inconsistent, but I haven’t thought about it. Whatever the
case, though, I just don’t see how that analogy is at all valid.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About