Print Story Perl currying, WW II books, pie, and cider
Diary
By tmoertel (Wed Nov 17, 2004 at 04:26:08 PM EST) (all tags)
I haven't posted in a while, and so I'm due for an update:
  • Adding near-free function currying to Perl.
  • Great books on WWII.
  • Maple-walnut pie.
  • Cider: Hard cider.


AutoCurry: Near-free function currying for Perl

One of the things I miss when programming in Perl is currying. (Oh my, how I do love currying.) There are some ways to simulate currying, but they typically rely upon a helper function to do the work, and calling it whenever you want currying is expensive enough to offset most of currying's benefits.

So, I wrote a small Perl Module called AutoCurry (strangely enough), that lets you have currying call semantics for nearly free. The idea is to introduce a currying notation that indicates that you want a function call to have currying semantics: Just tack an "_c" on to your function:

    sub foo { print "@_" }
    foo("hi");           # hi
    foo("hi", "joe");    # hi joe

    my $hi_printer = foo_c("hi");  # partial application
    $hi_printer->();     # hi
    $hi_printer->("joe") # hi joe

It's a cute hack, taking only about sixty lines of code. Behind the scenes I use a "double curry" on each target function and some symbol-table manipulatorianism.

If you want to know more, see my meditation on Perl Monks: Near-free function currying in Perl. Like all good meditations on currying in Perl, it contains a contrived and nearly worthless motivating example. (Enjoy!)

Great books on World War II

It all started with The Forgotten Soldier, a first-person account of a German foot soldier fighting on the Eastern Front. Haunting. The author, Guy Sajer, expresses the madness of war in a vivid telling of his experiences. He starts out in a simple convoy unit and ends up in an elite "named" infantry division. Through three drives into Russia and three retreats, unimaginable fatigue and starvation, and ultimately his capture by Allied troops, he lived a life of suffering in a few months. Recommended.

After reading that book, I wanted an Allied perspective. Thus I began reading Donald R. Burgett's series of books on his experiences as a paratrooper. Starting out with Currahee!: A Screaming Eagle at Normandy, he recounts his dangerous, rigorous training (during which several men died); the lead-up to the Allied invasion at Normandy; and his first drop behind enemy lines. Burgett doesn't have Sajer's skill for capturing subtle emotions, but his writing is vivid and candid.

Next up was Burgett's The Road to Arnhem: A Screaming Eagle in Holland about his drop into Holland for Operation Market-Garden. Burgett doesn't hide his feelings that British Field Marshal Montgomery made stunning errors that were paid for in young soldiers' lives. This book makes clear the importance of good leadership in times of war. Small errors at the top cost many lives at the bottom.

Presently, I am reading Burgett's account of the Battle of the Bulge: Seven Roads to Hell: A Screaming Eagle at Bastogne. (I am reading the books in order of WW II chronology.) This book is markedly more graphic and precise than the others I have read. Burgett's writing, already good, is now compelling. (If you read only one of his books, this is it.) In this book, he tells of being marched Bastogne to dig in and prevent a advancing German tidal wave from taking the vital roads which converge at the town. On the way, his unit passes countless retreating Allied infantryman who tell him that if he's going to the front, he's as good as dead. At Bastogne, the paratroopers are cut off from Allied support and completely surrounded by German forces. Outmatched nine to one and nearly depleted of ammunition, the cut-off solders nevertheless hold off the German attacks for over a week, until the Allied line could be reestablished.

I've got about four more WW II books in the queue. I'm looking forward to all of them.

Maple-walnut pie

What do you get when you roast 1.75 cups of fresh, shelled walnuts and bake them in a pie along with three eggs and 1 cup of real, grade-B maple syrup? You get an insanely delicious pie. So insanely delicious, in fact, that I a have had no choice but to bake four of them in the last few weeks. Despite attempting to "share" them with friends, I have eaten about two whole pies myself.

No regrets.

Cider: hard cider

Like all men of character, I disapprove of the modern-day practice of heat-treating cider. Sure, toxin-producing bacteria are undesirable, and sometimes deadly, but heat-treating cider is just plain wrong. Also, what's up with the filtering? If that's your game, just drink apple juice.

No, if you want safe cider, the best way is to let nature do its thing: Fermentation. In about ten days at room temperature, yeast in untreated cider ferments the sugars to the point where the alcohol content reaches about 6 percent by volume, effectively killing off the nasty little critters. (See Is Hard Cider for You? (PDF) for more.)

So about two weeks ago, with this knowledge in head, I bought a jug of untreated cider from a local orchard owner, fixed it to my kitchen counter, and let it rest. In a few days, the plastic jug had puffed up and there was a hissing at the cap, which I had loosened to allow the carbon dioxide produced during fermentation to escape. The top of the liquid was foamy, just like I remembered from my beer home-brewing days. This process continued for about five or so days and then subsided. I let it go for a few days more and then bottled it, adding a little priming sugar to allow for in-bottle carbonation. (Taste tests at the time were encouraging.)

In a few days, the final cider will be ready for its unveiling. I can hardly wait.

That's all for now.

Cheers,
Tom

< Wasted. | BBC White season: 'Rivers of Blood' >
Perl currying, WW II books, pie, and cider | 7 comments (7 topical, 0 hidden) | Trackback
Don't you get sick of the subject after 3 books? by bob6 (5.00 / 1) #1 Wed Nov 17, 2004 at 09:12:55 PM EST
That's odd because I just saw To be or not to be, a great (and profound) comedy set up in Poland during WWII.

Cheers.
Re: by TurboThy (6.00 / 1) #2 Wed Nov 17, 2004 at 09:18:50 PM EST
Sir, I salute you for having the time and patience required to explain currying to perlheads.

If you want a more elevated view of WW2, I can heartily recommend anything written by John Keegan on the subject (and, indeed, any other subjects).
__
Sommerhus til salg, første række til Kattegat.

Not even the hardest part by bob6 (6.00 / 1) #4 Wed Nov 17, 2004 at 09:46:48 PM EST
Try strong typing for a challenge.

Cheers.
[ Parent ]
Yes hello Sir by komet (5.00 / 1) #3 Wed Nov 17, 2004 at 09:24:01 PM EST
Now that you've seen Haskell with thine own eyes, how can you still program in Perl without puking?

More seriously, what criteria do you use when deciding whether to solve a given problem in Perl or Haskell?

--
<ni> komet: You are functionally illiterate as regards trashy erotica.

Currying or specialization without it by jacob (6.00 / 1) #5 Thu Nov 18, 2004 at 12:07:08 AM EST
Currying is nice, easy to explain, and very useful for theory, but for practical programming I'm becoming more fond of "specialization without currying" as explained in this SRFI. The basic idea is that currying only allows you to specialize a prefix of the functions arguments, so if a function happens to receive its arguments in a bad order you're screwed. The kind of specialization described in the SRFI, on the other hand, has no such limitation (at the cost of a smidgen of extra syntax). You might want to check it out.

--

Olabel style... \nt by bob6 (3.00 / 0) #6 Thu Nov 18, 2004 at 12:26:45 AM EST


Cheers.
[ Parent ]
Currying works well in the land of curry by tmoertel (3.00 / 0) #7 Thu Nov 18, 2004 at 12:39:22 AM EST
The thing is, when programming in a language with direct and pervasive support for currying (say, Haskell), most people naturally define their functions such that the arguments most likely to be specialized come first. As a result, you hardly ever need to specialize anything beyond the second argument, which can easily be accessed with the hof flip.

I can't say that I would welcome replacing currying with a mechanism like that in the aforelinked SRFI (thanks for sharing it, btw), because I think that it would increase the cost of specialization in the common case. Pipelines of partial applications are commonplace. To use my last PFC entry as an example:

showSolution . flip findMinWinSoln v . readStateStats
and
readStateStats =
   map mkStatsEntry . groupsOf 3 .
   map (filter isAlphaNum) . words
and
join = (concat.) . intersperse
I use currying so much that increasing its cost even a little bit in the common case would make it annoyingly expensive.

Now, currying and a template-like specialization feature would make a handsome couple.

Cheers,
Tom

--
Write Perl code? Check out LectroTest. Write markup-dense XML? Check out PXSL.

[ Parent ]
Perl currying, WW II books, pie, and cider | 7 comments (7 topical, 0 hidden) | Trackback