I can't think of one off hand that uses it for logging but why not?

You can't just pass a filehandle because then you cannot do interesting things with a message before logging it or maybe decide not to log it at all (unless you tie the filehandle but please don't go there).

The only other way that has the same flexibility is to pass in a logging object, which has a log() method.

When it comes down to it, a closure and an object with one method are pretty much equivalent, they both store a state and they both have a behaviour which can be invoked. The difference is that it's a lot easier to construct a closure on the fly whereas an object needs an entire class.

The Tk framework is full of things that take a callback. Tk programmers have to write lots of closures. I used to do loads of Tk work (back in the 2oth century :-) and looking back, I frequently found myself currying functions although I didn't have a name for it at the time.

Frameworks in functional languages like lisp and Haskell do this too because it's easy to do for them as currying is built in and is the "natural" way to do this for their programmers.


In reply to Re^4: Near-free function currying in Perl by fergal
in thread Near-free function currying in Perl by tmoertel

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!
  • 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, details, 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, summary, 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.