in reply to Re: Yet Another Program on Closures ~ Steven Lembark ~ TPRC 2025 - YouTube
in thread Yet Another Program on Closures ~ Steven Lembark ~ TPRC 2025 - YouTube

That's because Perl is true to the historical and generally accepted definition.

The term closure is often used as a synonym for anonymous function, though strictly, an anonymous function is a function literal without a name, while a closure is an instance of a function, a value, whose non-local variables have been bound either to values or to storage locations

The languages to which you allude would be "stretching the definition of an established term". An anonymous function without[edited] the ability to access a captured environment isn't a closure.

  • Comment on Re^2: Yet Another Program on Closures ~ Steven Lembark ~ TPRC 2025 - YouTube

Replies are listed 'Best First'.
Re^3: Yet Another Program on Closures ~ Steven Lembark ~ TPRC 2025 - YouTube
by choroba (Cardinal) on Jul 31, 2025 at 17:47 UTC
    > An anonymous function with the ability to access a captured environment isn't a closure.

    Do you mean without?

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      yeah :(

Re^3: Yet Another Program on Closures ~ Steven Lembark ~ TPRC 2025 - YouTube
by LanX (Saint) on Jul 31, 2025 at 18:25 UTC
    I think one should always give the source when citing a quote.

    In your case you seem to copy a paragraph verbatim from a Wikipedia chapter, which is unfortunate.

    Your definition seems to say that a function using global variables (which are "non local") is a closure. I'd say no! (Hence also the term lexical closure")

    In the end it depends how we identify mechanisms used in Lisp inside Perl for interpretation of the original definitions.

    Like "free variable" and "binding"

    Are global variables bound in Perl?

    I'd say no, they are looked up in the symbol table.

    No reference is stored in the lex pad of a sub.

    But is this an accurate definition of binding?

    (FWIW ... To increase the confusion, PadWalker is is capable to list non-local our variables, since they are lexical aliases to package variables)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      I think one should always give the source when citing a quote.

      I did.

      Your definition seems to say that a function using global variables

      Odd. Did I even even provide a definition?

      I'm certain I didn't come remotely close to opining about whether globals are captured or not.

      And you seem to be referring to package vars, which aren't global. Only punctuation vars and a few others deserve that name (ARGV, STDOUT, ENV, SIG, etc).

        > I did.

        Mea culpa, my phones display is broken.

        Still that's the opinion of a WP-author, not an original source or "historical ... definition"

        > Odd. Did I even even provide a definition?

        Well you literally said so:

        > > > historical and generally accepted definition.

        and then

        > > > "whose non-local variables have been bound"

        and package vars are "non-local".

        And than I pondered about the possible meaning of "binding" in Perl.

        to be more explicit

        :~$ perl -MO=Concise,Bla::func -E'package Bla; sub func { say $x }' Bla::func: 5 <1> leavesub[1 ref] K/REFC,1 ->(end) ... yadda yadda 3 <#> gvsv[*Bla::x] s ->4 # <--- is thi +s a binding? -e syntax OK

        > And you seem to be referring to package vars, which aren't global.

        Oh my holy lord of the nitpickers ... the full qualified names are globally accessible.

        This means that package vars can be manipulated outside the sub.

        > Only punctuation vars and a few others deserve that name (ARGV, STDOUT, ENV, SIG, etc).

        And those are just implemented as package variables in main:: , b/c any other surrounding package declaration is just ignored.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery