Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

Title:
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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (6)
    As of 2014-08-02 01:37 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Who would be the most fun to work for?















      Results (53 votes), past polls