On Fri, Mar 14, 2003 at 03:49:21PM -0500, Dan Sugalski wrote:At 10:14 AM -0500 3/14/03, Andrew Pimlott wrote:
>A6 says that, as in Perl 5, only anonymous subs are closures. I've >always thought of the fact that Perl 5 named subs are not closures >as a bug kept for compatibility.
Well... there's always the issue that closures are done by instantiating the sub at runtime, while named subs are instantiated at compile time, which causes some difficulties. (As the enclosing sub's lexicals instantiate at runtime, thus giving the contained sub nothing to close over)
I don't understand exactly what you mean, because perl's behaviour is rather strange and I don't know how it's implemented. Currently, named subs close over _something_, because they get the value of lexicals from the first time the enclosing code is run.
Yeah, the current behavior's kind of odd, and arguably broken. (And I'd not argue against that too hard)
At any rate, you're right that the fact that Perl 5 nested subs are visible globally means that talking about closure is basically nonsense. In my view, this is part of the bug. Nested subs should be visible only within their scope (or at least, there should be a way to declare them so that they are), in which case they would have to be instantiated at run-time (right?), and there should be no problem binding the current lexical variables.
Well, the "Named subs are always global" rule isn't a bad one, and is pretty common on top of that. Most of the used languages (C, COBOL, Fortran, BASIC, and a few others), at least at the time perl was getting built, did it that way if they even let you play nesting games. Yeah, I know, Pascal and its descendants didn't do it that way, but Pascal wasn't particularly mainstream in the large computer realm as anything other than a teaching language people hated because it was limited enough to be generally useless.
> Now, if the named lexically scoped sub actually got re-instantiatedevery time, *that* would be different.
Am I correct that Perl 6 lexical subs would have to get re-instantiated every time, or could you implement them such that they are not?
The subs themselves won't get re-instantiated--one compilation per customer--but you'd get a new set of metadata (scratchpads and such) each time through.
--
Dan
--------------------------------------"it's like this"------------------- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk _______________________________________________ Boston-pm mailing list [EMAIL PROTECTED] http://mail.pm.org/mailman/listinfo/boston-pm