On Fri, Nov 02, 2001 at 10:51:49AM -0500, Jeff 'japhy' Pinyan wrote: > On Nov 2, Etienne Marcotte said: > > >check out http://www.crusoe.net/~jeffp/articles/pm/2000-05.html > > > >a really good document on closures... > > Before I get a barrage of "BUT THAT'S NOT A CLOSURE!" let me say this. I > was told that by someone (can't remember who), and I asked merlyn (Randal) > what he thought (right, Randal?) and he said that a function like: > > { # $name exists ONLY in this block > my $name = "Jeff"; # $name is lexically scoped > sub whoami { $name } # we use the lexical $name here... > } # $name goes out of scope > > can be called a closure. I feel that "closure" refers more to the action, > and less to the means -- we are creating a subroutine (named or unnamed > makes no difference) which holds on to variables that "should" be gone.
Three points: 1. The current documentation refers to closures as anonymous subroutines. It doesn't state that named subroutines can not be closures, but it does always state that closures are anonymous subroutines, if it makes any distinction. 2. Damian Conway's excellent "Object Oriented Perl" explicitly states that named subroutines can be closures. 3. Currently, Perl exhibits some surprising behaviour in certain situations when a named subroutine is being used as a closure. In practice, Perl does not properly close named subroutines. Most people holding an opinion consider this a bug, although there is not general consensus, and it is difficult to fix anyway. There are no such caveats when using anonymous subroutines as closures. 4. Ideally, I would like to see both Perl and its documentation patched such that named subroutines can be safely used as closures. There are probably but a handful of people capable of doing that, and so far it has not been done. OK. Three points and a pipe dream. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]