develooper Front page | perl.perl5.porters | Postings from July 2009

Re: Brainstorming 5.12 syntax features

Thread Previous | Thread Next
From:
demerphq
Date:
July 16, 2009 12:16
Subject:
Re: Brainstorming 5.12 syntax features
Message ID:
9b18b3110907161216u6bb3fa3cu3865a9e47cb0bf2b@mail.gmail.com
2009/7/16 David Nicol <davidnicol@gmail.com>:
> On Thu, Jul 16, 2009 at 9:51 AM, Rafael
> Garcia-Suarez<rgarciasuarez@gmail.com> wrote:
>> Ah, so you were making the assumptions that the sub to call is known
>> at compile time and that it would never change during the lifetime of
>> the program. This is Perl, so those are wrong assumptions :)
>
> anyone for "local sub" shorthand?
>
> $ perl -le 'sub X {"outer"} { local sub X {"inner"} print &X } print &X'
>
> could become equivalent to
>
> $ perl -le '*sub X {"outer"}; { local *X = sub {"inner"}; print &X } print &X'

One problem with the bottom on older perls is it resets the method
cache for all methods, twice.

In newer perls I think things are better, I dont know how much.

The only need for this that i know of is if you dont have
Scalar::Utils::weakref() available for some reason, and you need to do
a recursive closure. And i personally think that case is much easier
to solve, (already (mostly?) solved actually thanks to rafael), by
having a symbol which always refers to the current sub, without
modifying the subs refcount. Which is more or less provided by
Sub::Current.

cheers,
Yves



-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

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