|
|
| laziness, impatience, and hubris | |
| PerlMonks |
Re^7: Yet Another Program on Closures ~ Steven Lembark ~ TPRC 2025 - YouTubeby LanX (Saint) |
| on Aug 01, 2025 at 18:33 UTC ( [id://11165915]=note: print w/replies, xml ) | Need Help?? |
|
> True, but irrelevant. What makes them global is that they can be accessed from anywhere. All package variables can be accessed everywhere. As I said > > This means that package vars can be manipulated outside the sub. > your example of a global variable uses our, which creates a lexically-scoped variable. Now this is indeed "irrelevant". They create a lexical alias to a package var. They are still globally accessible via full-qualified name. > And did you read the page? I even cited the original sources.
Anyway ...... my original question wasn't answered, if "a function using global variables (which are "non local") is a closure" Given that the original sources talk about binding "free variables" which are "bound" I tend to say "kind of". They are bound in the Perl's Op-Tree to their symbol table entry. But a (the?) central idea of closures is that of encapsulation and protection of those variables from external manipulations and other side effects. And this is not given with with package variables. A way out of this conundrum is to realize that Perl is not Lisp, and that "Closure" in Perl's context is a short for "lexical closure". Let's have a look what Larry says in Perl Glossary
But this definition is certainly stressing the "lexical" character of closures, with variables which survive even out-of-scope.
Cheers Rolf
In Section
Meditations
|
|
||||||||||||||||||||||||||||||||||||||||