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

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

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

Replies are listed 'Best First'.
Re^4: Yet Another Program on Closures ~ Steven Lembark ~ TPRC 2025 - YouTube
by ikegami (Patriarch) on Jul 31, 2025 at 19:22 UTC

    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

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

        No, Wikipedia pages are not one author's opinion. And did you read the page? It gives the history of the term.

        Well you literally said so:

        No, as you said, that came from Wikipedia.

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

        Fair. But not fair to say I claimed package vars are captured.

        Oh my holy lord of the nitpickers

        You are wrong.

        In normal circumstances, I call file-scoped my vars global, and so do many others. And others do the same for package vars.

        Neither are actually global, but that's perfectly fine in *those* situations. But clarity *is* required here.

        To what combination of file-scoped my var, package vars, and actual globals are referring when you say globals?

        And let's not forget that what appears to your example of a global variable uses our, which creates a lexically-scoped variable.

        So yeah, if you're going to ponder what constitutes a capture, requesting some specificity isn't nitpicking.

        And those are just implemented as package variables in main::

        True, but irrelevant. What makes them global is that they can be accessed from anywhere. This is not true of arbitrary variables in the root/main namespace.