develooper Front page | perl.perl5.porters | Postings from October 2003

Re: [perl #24250] "return" required in some anonymous closures

From:
Graham Barr
Date:
October 20, 2003 08:59
Subject:
Re: [perl #24250] "return" required in some anonymous closures
Message ID:
5DE7BB12-0316-11D8-8802-0003938857CC@pobox.com

On 20 Oct 2003, at 13:29, Elizabeth Mattijsen wrote:

> At 11:45 +0100 10/20/03, Dave Mitchell wrote:
>> On Mon, Oct 20, 2003 at 12:17:24PM +0200, Elizabeth Mattijsen wrote:
>>>  (I should stop answering my own posts  ;-)
>>>
>>>  At 11:55 +0200 10/20/03, Elizabeth Mattijsen wrote:
>>>  >Hmmm... both of the following return correct results also:
>>>
>>  > The problem can be simplified to the following code:
>>  > so this looks like an optimizer problem to me: the $get sub is
>>  > referring to something else than the package lexical $foo.
>> This isn't a bug, it's a feature :-)
>> sub () {$lexical} is a constant sub generator, ie each call to 'sub'
>> returns a new constant sub rather than a closure. It doesn't seem to 
>> be
>> well documented though. Been around since 5.8.0.

It is only supposed to generate a constant sub if there are no other 
references to the variable. ie there is no way the variable can change.

> I always thought you would need to document a bug before it becomes a 
> feature?  ;-)
>
>
> Seriously, I haven't been able to find _any_ documentation on this 
> feature.  It definitely is not mentioned in the 5.8.0 perldelta (or it 
> is described without the terms "constant" or "generator").

Constant subs were in 5.6.0 IIRC

> If this _is_ a new feature of 5.8.0, maybe it should be at least 
> documented in the 5.8.2 perldelta?  And possible somewhere else. 
> Suggestions for locations where this should be documented?  I'll write 
> up a description and submit a patch then.

I suspect it is a bug in the code that determines if a sub can be 
considered a constant sub and was introduced during 5.7 development

Graham.




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