>>>>> "M" == Marc Lehmann <[EMAIL PROTECTED]> writes:
M> On Tue, 23 May 2000, Perrin Harkins wrote:
>> Your sub &x is a closure.  That's why it returns the previous value of

M> No. In perl, a closure is *defined* as "anonymous subroutine" (see the
M> documentation). If you define it different, you are right, but you are not
M> talking about perl then.

What? Can we get a reference to your definition?

>From Camel book, 2nd edition, page 253:

    Closures

    Earlier we talked about creating anonymous subroutines with a
    nameless C<sub {}>. Since anonymous subroutines have to be
    generated somplace within your code (in order to generate the
    reference that you poke into some variable), such routines can be
    thought of as coming into existence at run-time. (That is, they
    have a time of generation as well as a location of definition.)
    Because of this fact, anonymous subroutines can act as I<closures>
    with respect to C<my> variables - that is, with respect to
    variables visible lexically within the current scope. Closure is a
    notion out of the Lisp world that says if you define an anonymous
    function in a particular lexical context at a particular moment,
    it pretends to run in that context even when it's called outside
    of the context. In other words, you are guaranteed to get the same
    copy of a lexical variable, even though many other instances of
    the same lexical variable may have been created before or since.

Also 'perldoc -q closure' and 'man perlref' agree with Perrin.

There is one ambiguous use of "closure" in L<perlsub> that I found
during my quick scan. Maybe that's what you're hanging your hat on?

>From 'man perlsub'

       Like many languages, Perl provides for user-defined sub-
       routines.  These may be located anywhere in the main pro-
       gram, loaded in from other files via the `do', `require',
       or `use' keywords, or generated on the fly using `eval' or
       anonymous subroutines (closures). 

Given the above more complete descriptions I would say the usage in
L<perlsub> is confusing. 

Hope you have a very nice day, :-)
Tim Ayers ([EMAIL PROTECTED]) who, against better judgement, as an
ex-Lisper just couldn't let this slide

Reply via email to