And if a named sub does, it's also a closure.
Indeed two unrelated concepts.
I just checked the etymology, the fact that the bound variables are not accessible from the outside of their defining scope makes the sub "closed".
{ my $state = 42; sub closed_sub { return $state++; } } say closed_sub(); # 42 say closed_sub(); # 43
Contrary to subs binding global variables, which are "open".
{ our $state = 42; sub open_sub { return $state++; } } say open_sub(); # 42 $main::state = 666; say open_sub(); # 666
(of course Perl allows you to bind both kinds, so it's not an exclusive attribute here)
see references from WP:
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
In reply to Re^3: Yet Another Program on Closures ~ Steven Lembark ~ TPRC 2025 - YouTube (UPDATE Etymology)
by LanX
in thread Yet Another Program on Closures ~ Steven Lembark ~ TPRC 2025 - YouTube
by LanX
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |