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 25, 2013 04:47
Subject:
Re: Lexical subs allow overriding if/else & other syntax keywords?
Message ID:
01A32EDC-828A-4878-AF48-B25880719849@cpan.org

On Mar 24, 2013, at 6:57 PM, Brian Fraser wrote:

> On Sun, Mar 24, 2013 at 6:00 PM, Father Chrysostomos <sprout@cpan.org> wrote:
>> 
>> 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.
> 
> Ah.. For whatever reason I was under the impression that the outcome
> of #108286 was disallowing the override of if/else/elsif/continue, but
> looks like my head just made that up. That was my argument for calling
> this a bug; Sorry for that noise!
> That being said, I feel the ickyness has moved elsewhere: if
> overriding *CORE::GLOBAL::if currently ignored, shouldn't the same
> happen for lexical overrides?

Well, eventually, I’d like ‘if’ to be overridable by more normal means.  That’s what I’m ‘working’ towards (quotations marks, because I’m not really doing much with perl right now :-).  Since lexical subs are in their own namespace, I can do those correctly right now, without worrying about backward compatibility.

> Otherwise, this introduces yet another
> special case to the language: 'if' can be lexicalized but not
> localized, which is inconsistent with both how other keywords work
> (which allow overriding both ways) and with how special variables work
> ('$$' can be localized but can't be lexicalized).

Well, there is *already* an inconsistency in that some keywords can be overridden and some not.  I would like to eliminate that.

> 
>> Conceptually, ‘if’ is in the CORE:: namespace.  Since lexical names take precedence over those residing in symbol tables, the lexical ‘if’ takes precedence here.
> 
> Aye, this makes sense.
> 
>> 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.
>> 
> 
> If I'm not mistaken, the keyword plugin happens before checking for
> any other overrides, so I'm pretty sure this is already the case?

Zefram wants to deprecate the keyword plugin, in favour of using sub lookup for all overrides.  I can see why, as it’s a bit heavy-handed.

> Or
> can you do a different sort of override with a lexical sub plus the
> keyword plugin?

I’m not sure I understand that question.

> 
>>> 
>>> 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