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

Other languages seem to use it other ways, including to mean any anonymous ... sub.

If an anonymous sub doesn't close over an external variable then it isn't a closure. The clue is in the name. :-)


🦛

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

Replies are listed 'Best First'.
Re^3: Yet Another Program on Closures ~ Steven Lembark ~ TPRC 2025 - YouTube (UPDATE Etymology)
by LanX (Saint) on Jul 30, 2025 at 18:09 UTC
    > 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