develooper Front page | perl.perl5.porters | Postings from March 2013

Re: Lexical subs allow overriding if/else & other syntax keywords?

Thread Previous | Thread Next
From:
Father Chrysostomos
Date:
March 24, 2013 21:00
Subject:
Re: Lexical subs allow overriding if/else & other syntax keywords?
Message ID:
0F267E13-6D11-4799-84F0-47A9D94CBAEF@cpan.org

On Mar 24, 2013, at 12:52 PM, Brian Fraser wrote:

> This might be a bug:
> 
> $ ./perl -M-warnings -Ilib -Mfeature=lexical_subs -E 'my sub else (&)
> { say "woah, what?"} if (1) {} else {}'
> woah, what?
> 
> As there's no way of getting that override with normal subs. However,
> similar behavior is tested for in lexsub.t, so this looks intended?

Yes!  That is as intended.  There is no intrinsic reason why ‘if’ should not be a function if ‘system’ is.  After all, they are both special keywords with special syntax.  Conceptually, ‘if’ is in the CORE:: namespace.  Since lexical names take precedence over those residing in symbol tables, the lexical ‘if’ takes precedence here.  Using one of Zefram’s magic modules, you could even attach a parser to your lexical ‘if’ to make it parse just like the built-in ‘if’, but perhaps with more features.

> 
> Since lexical subs are experimental I don't think is needs to be
> addressed right away, but it certainly looks icky.

Not icky at all. :-)


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