Sunday, September 16, 2007

LaTeX

Hah! I got MacTeX going on the new MacBook. I've missed being able to crank out decent-looking documents... It used to be that LaTeX of one form or another was the first thing I'd install on a computer. This time I've been slow on the draw. Still, the MacTeX installation is extremely complete, and I'm finding I have to do very little customization to make it work the way I want it.

What is LaTeX? It's a document preparation system based on Donald Knuth's legendary TeX. Rather than a word processor, it's a type-setting system. So it works a lot like HTML in a web page: you input plain text commands into a file, then run the LaTeX system against it. The system produces the document in an image-based format (I always generate PDF, but DVI or PS are common), which prints predictably on any decent printer (unlike, say Microsoft Office documents).

People who use TeX, LaTeX, or their ilk hold them in deeply religious awe. They are truly the ultimate in document preparation. Rather than using a word processor, which is designed to let you type out pages; you're using a type-setter, which is designed to produce books. So LaTeX documents have kerned, ligatured output.

I first learned LaTeX when I was unemployed and broke, but needed to generate some decent documents. I couldn't afford to buy a word processor, but I had plenty of time on my hands, so I downloaded LaTeX (which is free) and invested a lot of time learning it. It's not necessarily easy: there is a learning curve involved; but I had more time than money then, and I've never regretted the choice I made.

I still find all word processors primitive, inadequate, and kludgy. Pages is better than most, but even that's no LaTeX.

Anyhow, I've spent some time making sure all the fonts are in place, etc. and now I'm ready to get back to the world of nice documents...

Friday, September 14, 2007

OCaml, my love

I want to love OCaml, I really do. In fact, I want to love Haskell too, but OCaml seems just a little more pragmatic.

But in the end, there is something that keeps me from loving OCaml: I can't find a compelling use case. I can't see anything that's significantly easier to do in OCaml than in Lisp, for example. And while OCaml apparently make very fast executables, Lisp is certainly "fast enough."

OCaml doesn't seem to own anything I want to learn. Lisp owns AI, Erlang owns concurrency. I know, there are other options in both categories, but you get the point.

The most interesting feature I can see in OCaml from where I sit is the type system. No question, OCaml's typing is strong and static. From an outsider's point of view, it seems much like Haskell's; although I am sure devotees of either tongue would recoil in shock from such a suggestion. But the rigidity of the type system is a barrier to learning the language. You'd think there would be some sort of evangelism based on that; instead the OCaml-istas seem more interested in looking down on others for not having an adequate type system than giving examples of how such a system is a Good Thing.

I bought Practical OCaml, and I read it. More than once. But it fails to present me with interesting solutions to problems. Online tutorials have a similar problem "Look! You can add two numbers in OCaml!" Hardly worth learning another whole language, especially one with very different syntax from the ones I already know.

And when the language has a bondage-and-discipline type system, even adding two numbers seems inordinately difficult. I mean, in OCaml there is no auto-boxing that I can see... none! Even the arithmetic operators are different! "+." adds floats, "+" adds integers.

I suppose there is an opportunity here for me to learn OCaml and bring a decent book on it to market. Maybe I'm looking at this the wrong way.

So if OCaml isn't compelling, then why do I want to love it? I suppose because there are some interesting features in functional languages (like Haskell, OCaml, and Erlang) that intrigue me. One is the whole "clause" thing. Where a function in C might look something like this:

int add(int i, int j){
return i + j ;
}


And in Java it might look like:

public int add(int i, int j){
return i + j ;
}


That same function in OCaml looks like:

let add i j = i + j;;


But OCaml gets more interesting when you differentiate between inputs. So you could write some function that returns the sum of a list of numbers like:

let rec sum list = match list with
[] -> 0;
| head :: tail -> head + sum tail ;;


Actually, that's pretty cool: there are actually two definitions ("clauses") in the function. One is the definition of the sum of an empty list '[]'. That sum is zero. The other clause says if you get a list that has some data in it (i.e. a head and a tail), the function adds the head to the sum of the tail.

I suppose Lisp could do the same thing with DEFGENERIC, but I find the simpler recursive solution more intuitive:

(defun sum (LIST)
(if (null LIST)
0
(+ (first LIST) (sum (rest LIST)))))


So I suppose the OCaml version is shorter than the Lisp version.

Anyhow, I'm just rambling now. Programming is only interesting when you're learning something new. Right at the moment, my Java job is getting a little mundane. I had hoped OCaml would provide an interesting diversion, but it appears I was barking up the wrong tree.

Saturday, September 8, 2007

3.14159

Well, today being a Saturday, and we having too many apples, I made some apple pies today. They might be the ugliest pies I've ever made, but they're pies. Apple pies.



Actually, they were a bit of a team effort. I made the pastry too dry (and I used whole-wheat flour), so I broke it several times trying to roll it out. Eventually Ames stepped in and got me some pie shells from the mess I made.

I finally fixed my pastry, but not until it was pretty much too late. Ames takes credit for the nicer of the two pies.



How did I make the pastry? you ask. Well, I used the Tenderflake Perfect Pastry recipe. It's the only one I can get to turn out for me at all. And yes, I used lard. I live in the South. I actually would have used shortening, but I ran across some lard in a cupboard, so I thought "why not?".

It turns out we're missing a pie plate again. Apparently there's a gremlin in our house that steals pie plates: it seems we're having to buy pie plates very frequently. At any rate, we used the one pie plate we have, and I got Ames to roll out the other shell and put it into a glass casserole dish. In the end, I re-worked the pastry scraps into a new "batch" and was able to get it to roll. So I took that pastry, rolled it out, and put it in a cast-iron skillet. Ugy, but it works. I then used the shell Ames made me for a lid. That was a flop, and resulted in the mess in the photos.

Now, there's been some whining about my not including recipes in my blog. Let me set the record straight: there are at least three reasons I don't include recipes:

  1. I personally hate reading recipes. I find technique more interesting than recipes; and when I read something with a recipe in it, I simply skip over the recipe(s) and keep reading.

  2. I'm unsure the legality of posting a recipe I didn't invent. I post my own (when I keep track of them), but hesitate to post someone else's

  3. I almost never use recipes. If there is something specific I want to make, I do so. But the vast majority of my cooking is done on-the-fly. I may refer to a recipe, but I rarely follow one.


So for those who are criticizing my lack of recipes, please understand I usually don't have one to post.

But I'll gladly share how I made the pies.

First, I read the recipe in A Century of Canadian Cooking. Their recipe calls for the following:

  • 5 apples

  • 1 Tbsp. lemon juice

  • 1 tsp. cinnamon

  • 3/4 C. granulated sugar

  • 1 Tbsp. butter


You're supposed to peel and core the apples, then combine everything but the butter. After than, you dump it in a pie shell and dot with butter, then you bake for 15 minutes at 425F, then reduce heat to 350F and bake 35--40 more minutes.

Fine.

I thought brown sugar sounded better than granulated sugar, so I put brown sugar in a bowl. I ran 5 granny smith apples through my apple slicer; then I realized it wasn't enough and I was out of granny smith, so I ran a couple small red apples through too.

I thought 1 tsp. cinnamon sounded stingy, so I dumped enough in to cover the sugar.

I couldn't find any lemon juice, and Ames assured me we had none; so I thought "Well, rum's pretty close to lemon juice." I measured 1 Tbsp of rum over the sugar and cinnamon. Then I realized I was intending to make two pies, so I put another Tbsp of rum in there.



I was going to put another 3/4 C of sugar into the mix, when I realized I had snapped my 1/4 C measure with the first 3/4, so I grabbed a 1 C measuring spoon, got it 3/4 or so full of brown sugar, and dumped it in. Then I added more cinnamon and whisked it all together.

It looked a little dry, so I poured in some more rum.

Now I had a nice rum-sugar-cinnamon mixture, so I put in all the apples (I think I had six or seven at this point). I got it all mixed up, and realized I had made a sort of redneck Rumtopf. I put as much of that as looked reasonable in the first pie shell (which was almost all of it), and had one of the kids put some butter here and there on the apples. It was supposed to be 1 Tbsp. of butter dabbed on the apples, but my daughter was a little over-zealous, and it ended up being quite a bit more than that.

I rolled out a lid, and covered it. The lid broke terribly, so I just sort of jammed it all together and had one of the kids jab some holes in it.

By now, the second pie needed doing. I didn't have enough apples left, so I peeled and cored 3 or 5 more, and threw them into the remaining rum juice. I put some more cinnamon in there, and a dab more rum, then I threw in a handful or so of raisins and mixed it all up.

I put that mixture into the pie shell Ames had put in the casserole dish. At that point, I fixed the pastry, rolled out what was supposed to be a lid, realized it would be a good shell, and put it into the skillet. Then I up-ended the casserole dish over the new shell, and used the pastry from the casserole dish as a lid for the pie. Oh, and I remembered to put some butter over the apples before putting on the lid.



So I can't post my recipe, because I have no idea what is actually in those pies.

Oops.

Thursday, September 6, 2007

Holly and Ivy

Every year I look for a CD of Christmas music that will become the Christmas CD that year. Actually, I generally allow two such CDs per year. Since I listen to "Christmas music" all year (primarily of the hymn sort: "Hark the Herald Angels Sing" and so forth), I get a much wider window of opportunity to find that CD.

Over the last couple years, the title "Christmas CD of the year" has been bestowed upon several worthy albums, including:

  • Wintersong by Sarah McLachlan

  • Happy Holidays by Jo Stafford

  • Christmas with the Academy by The Academy of St. Martin-in-the-Field

  • Noel by King's College Choir

  • In the Moon of Winter by Northern Variations

  • December by the Moody Blues



So my tastes range somewhat. I like tacky Christmas music in December, but I really prefer more classic sounding stuff.

Well, last night I found one of the CDs for this year: A Traditional Christmas Carol Collection from The Sixteen, by Harry Christopers and The Sixteen. I've had trouble finding it at places like Amazon, so I just bought it from iTunes.

Now this will sound a little bold, but I put this CD slightly above Noel and Christmas with the Academy. The repertoire is very similar, and performance is about equal. But the difference is recording quality. Where the other two albums consist of tracks recorded as much as 40 years ago, this CD is all new. That is, the sound is much more three-dimensional; the high notes soar, the low ones surround.

I was honestly shivering at the beauty of the sound.

What songs does it have? There are the standby carols: "The Holly and the Ivy," "O Little Town of Bethlehem," etc. But there are the better ones that make a CD worth purchasing: "See Amid the Winter's Snow" and "The Sussex Carol."

That's one task off the Ber Month checklist.

Note: After posting the above, I found the CD at Amazon: A Traditional Christmas Carol Collection. Why couldn't I find it last night?

Tuesday, September 4, 2007

Four fried chickens and a coke

A few weeks ago, I wrote about deep frying in the South. Today we got to test some of my theories.

Yesterday was Labour Day, so we had some friends over. As my friend was cooking a dozoen potatoes in the deep fryer, he mentioned frying whole chickens. I was manning the grill while he took the fryer, but my thoughts went to a couple chooks waiting patiently in my refrigerator. So today when Ames called me at work and asked what I wanted for dinner, I said "We're going to fry those chickens!"

And we did.

Ames started out by battering the whole chooks. She used a "recipe" based on her mother's chicken batter: "A little salt, a little pepper, some flour." Ames' batter consisted of several spices, including paprika, which gave it an orange tinge:


While Ames was making sure the chickens were completely covered in their batter, I was starting the turkey fryer. I mentioned it in the other post: it's a 34-quart fryer. I took some pictures:


Yeah, that's the trash can in the background.

The oil in the fryer is still relatively new. We basically only fry potatoes, so it takes a while for the oil to darken. I only change the oil every 12 or 18 months: of course, cooking chicken in the oil will require a change in the next week or so. I think we'll try and get in a fish fry in there.


Then we dropped both chickens in the oil.

It got to be difficult to maintain the temperature between 325F and 350F. I ended up cutting the gas almost entirely, and the temperature still stayed too high.


After 20 minutes, we took out the chooks and cut one open.
It was still a little soft inside, so we put them back in for another 5 minutes:


Well, the chickens were done after the additional 5 minutes, so we took them out. And cut them up.




Add a little potato salad, and you have a winner. The potato salad had a slight orange hue, due to the paprika and red-skinned potatoes. I guess it was the day for orange tint.

The verdict? Excellent.

Lisp moment

So I had one of those "Aha!" moments this weekend. I was working on an HTML parser in Common Lisp. The "why?" isn't terribly important: I have a lot of data in HTML I want transformed into PDF. Rather than do it by hand, I figured it would be a good opportunity to try it in Lisp.

I've written a Lisp HTML parser before, but I was never quite satisfied with it; so I decided to start again from scratch.

Well, I was working on a recursive function that walks through an HTML string and turns it into valid Lisp, so this:

<html>
<head>
<title>Some Title</title>
</head>
<body>
<h1>Some header</h1>
<p>Some paragraph containing <a href='#'>some link</a></p>
</body>
</html>


Should get converted to:

(html
(head (title "Some Title"))
(body (p "Some paragraph containing" (a "some link"))))


Not exactly rocket science, but it has the advantage of generating valid Lisp as an output format. That way, I ought to be able to define functions "html", "head", "title", etc. that know how to render their arguments, and I have used HTML to generate a Lisp program that generates a PDF. Slightly circuitous, but a good pet project to learn some Lisp nuances while I get a tedious task done.

Notice too my example dropped the attributes for the <a> tag. That's because I haven't decided how to handle tag attributes yet.

Well, I was working on that piece of code (so far just under 100 lines and generates the Lisp: I need to write the compiler next) when I had a sudden flash of insight.

Functional programming is essentially applying a series of transformations to data.

OK, that is oversimplifying a little, but consider this example. Suppose we want to write a function in Lisp that doubles each element of a list. With no error handling, type-checking, etc. one might write something like this:

(defun double-list (some-list &optional accumulator)
"Double every element in a list."
(if (null some-list)
(nreverse accumulator)
(double-list (rest some-list)
(push (* 2 (first some-list))
accumulator))))


OK, OK, it would be easier to just do something like this:

(defun double-list (some-list)
"Double every element in a list."
(mapcar #'(lambda (x) (* 2 x)) some-list))

But that wouldn't make my point so clearly!

But in the end, I finally saw something I hadn't seen before: the work is done entirely in the call to the next function. That is, successive calls to the function only transform the data, then call the function again. So essentially the only work done in the function is to decide what arguments to use when it calls them again.

OK, that's rather simplistic. I mean, that's not really worthy of writing a book or anything, but it helped me understand a little better why functional gurus keep going on about applying successive transformations.

I guess it all comes back to what I said to a buddy a year or so ago: "Recursion is just iteration that keeps its state on the call stack."

Saturday, September 1, 2007

The Ber Months

Well, today is September 1, the official start of the Ber months. These four months: September, October, November, December are my favourite months of the year. In actuality, I enjoy January too, but it's not quite a Ber month.

In the end, I like the Ber months because my favourite seasons are winter and autumn (in that order). Here in North Carolina, that doesn't mean much: the weather is always relatively warm and balmy, even in winter. But it's a respite, however slight, from the blazing heat of the sun, which is almost a constant in the South. Sure, it would be better if the Ber months were also the Brrrrr months; but here in the South that's a bit much to ask.

This summer has been brutal. We've broken a couple records: the heat went up past 100F any number of times in the last 6 weeks, we're on water restriction, and the grass is all dead.

Let the Ber months begin!