Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Maybe I'm missing something important here, but a closure is not necessarily fully stocked with all the enclosed memory space and data it will need, because this is always possible:

    {
        my $x = 'default';
        sub xify_foo {
            my $foo = shift;
            $x = $foo->$x(@_)
        }
    }


    xify_foo needs to get more information from the stack, so it's not an entirely closed operation. Your explanation may apply in part, but I always thoug
    --
    rjbs
    • In your example, xify_foo by itself has one free variable: $x. $foo isn't free in xify_foo: it's given by the caller. Hence, xify_foo only needs to close over $x. Technically (at least by my way of thinking when I wrote the journal entry), the xify_foo closure has all the memory space it needs: $x in the closure, and $foo on the stack. That is, of course, nit-picking.

      This is the sort of thing I was handwaving about when I mentioned predicate logic. I suppose I should've gone into more detail. :-)

  • Closures come from ALGOL in 1960. That language is a direct ancestor of C and Pascal.

    They were borrowed from there by Scheme circa 1975 or so. And after that rapidly expanded through other Lisp dialects. Now the only commonly used Lisp that does not support closures is EMACS Lisp. (Which also doesn't support tail-recursion, also popularized by Scheme.)

    As for why a closure is called a closure, I think that the phrase, "closes over the environment" is highly suggestive...