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

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

From:
Dave Mitchell
Date:
October 20, 2003 16:53
Subject:
Re: [perl #24250] "return" required in some anonymous closures
Message ID:
20031020235312.GB5535@fdgroup.com
On Tue, Oct 21, 2003 at 12:05:44AM +0100, Nicholas Clark wrote:
> On Mon, Oct 20, 2003 at 11:53:03PM +0100, Dave Mitchell wrote:
> > Thus, I like Elizabeth's suggestion of using a compile-time attribute
> > to explicitly turn on this special behaviour, and thus to not suprise the
> > ordinary user.
> 
> I like it, but I'm worried that I may be hasty, so I'd like to to simmer
> for a bit more before committing anything half baked to maint.
> (Woohoo. Mixed metaphors. Flavour clash)
> 
> It would be nice if this (or something related) also provided a solution to
> how to export constants that can be autoloaded. Currently all the core
> extensions (such as Fcntl, POSIX, Socket ...) have @EXPORT or @EXPORT_OK
> full of names of "subs" that are actually defined as needed by AUTOLOAD
> (these days usually by a call into code generated by ExtUtils::Constant,
> but that's not important).
> 
> As these "subroutines" are actually constant value returning, it would
> be nice if
> 
> a: there was a way to declare them them from henceforth to be constants
>    without getting the prototype redefinition warning. (And its implication
>    that you're making a real change to the parsing behaviour)
> 
>    (Maybe I'm confused. Maybe we just need Exporter to declare them with
>     a prototype) (Without making it slower)
> 
> b: there was a way to make the tokenizer/optimizer whatever call the sub
>    to find the value whenever it is referred to. (given that it's actually
>    a constant sub)
> 
> Note that you can't simply call the AUTOLOAD routine on all the subs as
> you export them, as there are bazillions, and most are not used by most
> programs.

I'm not sure I understand all of the above, but...

An idea occurs to me.

Ilya introduced a patch that allowed stash values to be an IV or a PV
rather than a full-blown GV+CV when a sub had only been declared rather
than defined (IV => no protoptye, PV => protoptye with the PVX containing
the protoptye string).  Only later when the sub was actually defined was
the IV/PV replaced with a full GV containing a CV. This allowed Exporter
to whack lots of sub declarations into the caller's namespace without a
big memory overhead.

I wonder whether this idea could be extended - so for constant subs where
the package has no other variable of the same name, then rather than
having a GV pointing to a const CV, the stash just contains a "something"
(perhaps a PV with the right flags set) that actually holds the const
value. This PV would be shared by each packahge that imports it.

We would have to provide mechanisms
a) for the module to create all the values in its own namespace when
compiled;
b) for Exporter to cheaply copy these to the callers namespace.

Here endeth the 1am vague handwaving. Time for bed (said Zebedee).

Dave.

-- 
In my day, we used to edit the inodes by hand.  With magnets.



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