Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
...they are mostly structured and organized - not 50 line anonymous subroutines defined in the middle of another subroutine, with access to the parent's local variables even after it has returned.
I don't think that's a fair characterization (the sub shown is only 5 lines, and 2 of those are comments), and certainly isn't the point.

The parents "local" variables are lexical, and they are created explicitly for the closure. If I bake you a turnover, serve it on a paper plate, and give you a plastic fork to eat it with, should I be annoyed that you still have the plate and fork, or worse, have recycled them when you finished?

What if each object needs a unique compare function?
Then what are you comparing it to? I would have thought similarity was a prerequisite for comparison.
Sorry, that should say each pair of objects. More descriptively, what if each object is a collection, and needs a unique next method? But there are so many of unique collections that you can't precode classes for all of them? Which suggests similarities to Streams, which comes back to HOP.

What if these functions aren't known at compile time?
Closures are compiled too. That is, whether you use gt or > (or whatever) is decided at compile time. Its just the variables that change.
Ah, you see the gap approaching? Whether to use gt or > can be decided at compile time, but doesn't need to be. The leap of insight is that some higher caller can pass in a coderef to use in place of any predefined notions of how a comparison function should work. If the closure is coded well -- no unnecessary assumptions, just the fundamental "give me a coderef that I can pretend is a comparison function" -- and then the closure is more general and more useful than was ever imagined.

For an example, see the opening chapters of HOP, where the <code>dir_walk<code> directory walker function is gradually transmogrified into a generic traversal function, then used as a web spider.

In the end, it's the tool you know that gets used. It took me 3 days to put together one of those Walmart entertainment centers. Then I discovered electric screwdrivers, and never looked back.

-QM
--
Quantum Mechanics: The dreams stuff is made of


In reply to Re^6: How A Technique Becomes Over-rated by QM
in thread How A Function Becomes Higher Order by Limbic~Region

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
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 cooling their heels in the Monastery: (1)
As of 2021-06-19 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (92 votes). Check out past polls.

    Notices?