24 June 2007

Math links

A mathematician's apology (PDF). The early chapters are mostly grumbling about getting old. But then he starts talking about mathematics, with real poetry and love for the subject. Very nice.

Eudoxus. This ancient Greek anticipated Dedekind cuts and calculus. He also mapped the heavens and the earth. Yet no work of his survives--only frequent citations in the works of Euclid, Aristotle, Hipparchus, and more.

Triangle centers. Every triangle has a centroid. But oddly enough, that isn't the only center of a triangle. MathWorld has a picture showing over a thousand of them.

To do

Frivolous projects I would undertake, if I only had the time.
  • Submit a patch to Monotone that makes "mtn log" display log entries in chronological order.

  • Finish debugging the new, faster syntax-case implementation I have for Try Scheme. (sigh) It's so close!

  • Write about continuations.

    A good tutorial would be helpful. I haven't read anything I really liked. (Squawk of the Parrot has some very nice stuff on this.) I think a good approach would be to say up front that it's extremely generalized and hard to explain, but that we're going to work toward the definition. Then lean heavily on examples and analogies. Compare continuations to all kinds of control-flow concepts: functions; goto; return and break as functions; savepoints in video games; exceptions; generators; longjmp. Explain that all of these can be implemented fairly easily using call/cc. Then talk about continuation-passing style.

    I also want to investigate just what abstraction boundaries are violated by first-class continuations in a language that has state. I am kind of down on continuations as a language feature at the moment.

  • Read about continuations. In particular, Andrzej Filinski's thesis introducing the symmetric lambda calculus.

21 June 2007

Rooftop lab

I just started a new blog for my Mozilla work. It's called Rooftop Lab, and it'll be pretty technical.

19 June 2007

On the Cape

If you happen to be on Cape Cod sometime, visit Scargo Pottery, just off route 6A. That whole stretch of 6A is like a sprawling crafts fair, but Scargo is something special. The little pictures on their web site don't do it justice.

We were on Cape Cod for my birthday. It's a few weeks yet before the tourist season, but the weather was cooperative. Breezy, cool, sunny. Buzz was on his best behavior all day.

First we went to the Cape Cod Potato Chip factory. There's not much there, but you get to see a real factory floor. And eat potato chips. So.

Then we went to a little clock shop on Route 6A. Buzz was entranced. We talked about the clocks for, I don't know, it must have been half an hour. His favorite part was the clocks that had their faces removed so you could see the works.

After that, we went back to the beach, flew kites, climbed around on some rocks, and cooked out. A lovely day. If kites hate you, what you want is a Pocket Parafoil (here's one on eBay). Fun and ridiculously easy.

17 June 2007

Strawberry alert

If you happen to live in Nashua, NH, there's a small farmer's market on the Main Street bridge over the Nashua River. It's there every Sunday, all summer. A booth there is selling strawberries that were picked this morning.

15 June 2007

Woody goes to the park

A. is 22 months old now and insists on being called “Woody”, except when she's “Steve”.

Mommy: What did you do at the park? Did you slide down the slide?
Woody: Yeah.
Mommy: Did you run around?
Woody: Yeah.
Mommy: Did you meet some other kids?
Woody: Yeah.
Mommy: Did you eat some blueberries?
Woody: Yeah.
Mommy: Did you see a zebra?
Woody: Yeah.

08 June 2007

Productivity through eccentricity

From The Pmarca Guide to Personal Productivity (click the link, it's interesting):

[R]efuse to commit to meetings, appointments, or activities at any set time in any future day.

As a result, you can always work on whatever is most important or most interesting, at any time.

Want to spend all day writing a research report? Do it!

Want to spend all day coding? Do it!

Want to spend all day at the cafe down the street reading a book on personal productivity? Do it!

When someone emails or calls to say, “Let's meet on Tuesday at 3”, the appropriate response is: “I'm not keeping a schedule for 2007, so I can't commit to that, but give me a call on Tuesday at 2:45 and if I'm available, I'll meet with you.”

Or, if it's important, say, “You know what, let's meet right now.”

Clearly this only works if you can get away with it. If you have a structured job, a structured job environment, or you're a CEO, it will be hard to pull off.

But if you can do it, it's really liberating, and will lead to far higher productivity than almost any other tactic you can try.

There's more; if this bit appeals to you at all, the whole thing is worth reading.

By odd coincidence, pmarca is Marc Andreessen, cofounder of Netscape.

Credit: Marginal Revolution.

05 June 2007


In Scheme and Ruby, procedures that modify variables or data structures are marked with a ! by convention:

  // Java
  static <T>
  void arraySwap(T[] arr, int i0, int i1) {
      T tmp = arr[i0];
      arr[i0] = arr[i1];
      arr[i1] = tmp;

  ;; equivalent Scheme
  (define (vector-swap! v i0 i1)
    (let ((tmp (vector-ref v i0)))
      (vector-set! v i0 (vector-ref v i1))
      (vector-set! v i1 tmp)))

What's the point of this convention? Well, Scheme thinks this kind of behavior is slightly dangerous and needs to be highlighted. A little explanation:

If your variables or data structures can be changed, expressions have different values in different places within a program. The order of operations matters. The order of lines within a procedure matters. Procedures can subtly change global data as a side effect, and this can lead to rather subtle (mis)behavior.

Theorists call this language feature state. The word is intended in the sense of status, as in “the state of affairs” or “state of the Union”. C, C++, Java, Perl, Python, Ruby, and so on are stateful languages.

Maybe it sounds kind of, er, sweeping, or maybe absurd and stupid, to say that state is bad. But you already know this is true, at least sometimes: Global variables = bad. Unobvious side effects = bad. Leaving an operation half-finished when you throw an exception = bad (usually). Global state + threads = migraines.*

But what's the alternative? Well, there are alternatives, but it's beyond the scope of a quick blog post. Just like the boundary between static-typed and dynamic-typed code, the boundary between stateful and pure-functional code is getting a lot of attention these days. Interesting times.

What Scheme gets wrong here is that state-related bugs don't necessarily happen at the places where data is modified. In fact, the whole idea of marking the danger spots is a total whiff. The problem with state is that it permeates your program. The danger is everywhere a stateful variable or data structure is used, whether for read or write, directly or indirectly.

*It's not just that there are race conditions and potential crashes here. You can eliminate that with a single global lock. The problem is that a single global lock often isn't fine-grained enough; it creates a bottleneck. So you go to a fine-grained locking scheme, and that's where the migraines come in.

03 June 2007


I've been working through Types and Programming Languages by Benjamin C. Pierce. It's filling in a lot of blanks for me.

According to the drafts, ECMAScript 4 will have an ambitious new type system with optional type-annotation. So for example you could write:

//code without types
function sortLines(text) {
    let lines = text.split(/\r\n?|\n/g);
    return lines.join("\n") + "\n";

// or with
function sortLines(text : String) : String {
    let lines : [String] = text.split(/\r\n?|\n/g);
    return lines.join("\n") + "\n";

Exactly what effect these annotations will take some explaining. Suffice to say, life is about to get really interesting. I'm sure I'll be writing more about this in a few weeks.