Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I think the "normal CS definition of a closure" is a pretty elusive beast; mythical, maybe.

The The Free On-line Dictionary of Computing's

a closure is a data structure that holds an expression and an environment of variable bindings in which that expression is to be evaluated.

works for me.

A closure is code that retains a binding to a free variable even after the variable has gone out of scope.

Close enough :-)

I suggested that the closure is actually created when the sub is first entered via the goto.

So is this a closure?:

{ my $foo = 99; CODE: print ++$foo, "\n"; } goto CODE;

I don't think the above, or your original example, meet your or my definitions of a closure.

The variable bindings are not retained - because we don't get 100, 101, etc. That binding is an essential part of what a closure is all about.

Really, it's very similar to broquaint 's "named closure" example; only, the inner block is not a subroutine

I don't think it is because "named" closures retain the variable bindings of their scope they were declared in.

I do agree with you and broquaint that the Camel's definition is off. Closures and naming are separate concepts. It seems to be one of those things that Perl defines differently from the rest of the world :-) Why should a closure suddenly become something else if its assigned to a symbol table entry.

In reply to Re^4: Closure on Closures (beta) by adrianh
in thread Closure on Closures by broquaint

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (3)
    As of 2021-01-23 05:51 GMT
    Find Nodes?
      Voting Booth?