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

> If an anonymous sub doesn't close over an external variable then it isn't a closure.

And if a named sub does, it's also a closure.

Indeed two unrelated concepts.

UPDATE

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

  • Comment on Re^3: Yet Another Program on Closures ~ Steven Lembark ~ TPRC 2025 - YouTube (UPDATE Etymology)
  • Select or Download Code