Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: uninitialised variable (definition "closure")

by LanX (Saint)
on Dec 30, 2016 at 14:39 UTC ( [id://1178660]=note: print w/replies, xml ) Need Help??


in reply to Re^2: uninitialised variable
in thread uninitialised variable

> A closure is a function that returns another function,

No a closure is (in normal speak) only a function which is accessing variables outside from it's own body at declaration time.

The surrounding is not necessarily "another function" and the closure function is not necessarily "returned".

Technically the combination

  • function plus
  • "enclosed" variables

is called closure!

see Closure_(computer_programming)

Most people ignore these variables as implementation detail and keep concentrating on the "closure function" calling it simply the closure.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

update

Here an example of getter and setters implemented as closures which don't fall under your definition.

{ my $a; sub get_a { return $a } sub set_a { $a = shift } }

Update:

more examples here perlfaq7#What's-a-closure%3f

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1178660]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found