Monthly Archives: May 2008

Conditions in Common Lisp

Dan Weinreb wrote a long blog post recently outlining what Common Lisp’s “Conditions (exceptions) are really about.”  He argues, and I won’t disagree, that they provide a clean, even elegant, way to handle all the long tail of situations that arise when your trying to be fastidious about the contract for your functions.  One of the things that used to be unique about Lisp was it’s elegant support for unwinding the stack when odd things forced you to abandon what ever your doing.  It was a lot easier to see to it that the printer handle was relinquished, the file closed, the gate shut in Lisp than it was in Fortran or C.  These days most languages are better about admitting that these things happen and something should be in the language to help.

Interestingly though the Common Lisp condition system remains a much more elegant thing than you find in other languages.  I don’t really understand why.  The condition system doesn’t just provide a way to unwind the stack, passing along an object instance to describe what ‘exceptional’ condition arose.  It also allows the handler for these conditions to resolve them.  In effect this provides an elegant way to implement call backs, i.e. that situation where a low level body of code needs to ask the higher, or later written, code how to resolve a problem.  For example you can use the condition system to implement the classic call back scenario where a GUI widget wants to provide it’s users with the ability to do additional checking on user input.

There’s more, but what I really wanted to get off my chest (and that’s what a blog’s for eh?) is that I sometimes I like to muse about raising a condition is yet another example of how complex function calling really is.  Back in the day we used to be able to figure out what function would implement a call site at link time.  Later we got used to having dynamic linking do some of that, and it was common in memory constrained systems to load and flush code on the fly under the covers when in the function call.  I’ve seen systems where you switched interpreters in the function call for performance and space trade off reasons.  These days people are used to having a complex method dispatch that puzzles out what method will will take care of the request.  The method dispatch is a messy beast when you allow new classes to be loaded.  It was with some pleasure that I first read the mythical man month’s description of how some ornate linker came to be obsoleted; since at the time I was struggling with how loading compiled lisp files was an amazingly disruptive event; since it upset all your method tables.

Generally method dispatch is done by searches up stream in the acyclic directed graph of types.  I.e. the behavior of the function is inherited from the class hierarchy.  The class hierarchy is not the only hierarchy in most programs.  For example there is almost always a containment hierarchy, i.e. the OK button is inside this dialog; or for example this file write is taking place inside the task of writing the log, inside the task of handling this web request.

At one point in my life I was quite enthusiastic about the idea of language designs that might allow these other hierarchies more respect.  During that period I built a few class systems where behavior was inherited first from the containment hierarchy and only secondarily from the class hierarchy.

What I like about conditions is how when a condition is raised and the system goes off seeking a handler for that condition – it’s just another variant of method dispatch – and the call hierarchy is were we search for the handler.  For me the fact that these calls often don’t return; or return in such unusual ways is part of what’s delightful about the condition system.

Man’s work – depolarization

barfight.jpgThis is a long, interesting, carefully written article by Alex Kotlowitz about a program to change community behaviors in service of decreasing violence. It is nice to see a discussion of how to reduce polarization. There is so much entertainment value in polarization that the media revel in it. It is further to the article’s credit that it doesn’t play the card of Chicago’s most recent violent troubles into the text.
If I was to be critical of the article it would only be how it leaves the impression that the means being used here were entirely gin’d up by the folks involved. I certainly hope that many of these were imported from other violence reduction efforts, and most of the methods outlined I’ve read about in other venues; particularly the negotiation handbooks.

Given my interest in group dynamics I was interested by the story about a kid who wanted to resign from a gang. Much negotiation through various possible outcomes, “no”, “well, maybe, after a beating,” until they settled with the kid paying a fee. Not unlike getting out of your cell phone contract, eh? Joining a group often involves a hazing, and I suspect leaving often involves a beating – or at least a standing debt.  You can’t make the books balance in such situations. They never balance between members inside a club, that’s the point, so you can’t make them balance when you exit.

That groups are a sources of violence is clear. You get discipline inside, and polarization between, but I hadn’t noticed before that movements of members across the group member boundaries can also generate violence.

One other thing that caught my interest, because it’s analogous to atomization effect we see in other systems these days. “Many of the interrupters seem bewildered by what they see as a wilder group of youngsters now running the streets and by a gang structure that is no longer top-down but is instead made up of many small groups – which they refer to as cliques – whose membejoebenadam_ahd.jpgrs are answerable to a handful of peers.” When the middle scale systems die off you left with nothing but long-tail, and elites in their walled-gardens.

The skills these “interrupters” have are skills that we all should have. Skills the media should model. A culture rich in these skills can tolerate a lot more diversity. That there is honor in turning the other check. It is man’s work to intervene in a fight. The article is here.

Gas Tax

To be clear I think we should treat petroleum consumption as a sin and tax it accordingly. Because it’s: a) murdering the planet, b) it’s a principle contributor to the war, c) it’s running out and we need to accelerate the switching to alternatives, and d) the cost comes out of producer pockets, and e) it’s funding people who in many cases are coming to despise us.  I think lowering the tax is extremely bogus idea and a horrific diversion from other topics.

I gather that economists believe[1,2,3] that gas prices are largely unaffected by the gas tax. (That tax pays for highway maintainance, so it’s more like a user fee than a tax.) In fact I’ve heard it argued that if we raise the gasoline tax the effect will be to reduce the incomes of oil producers. I accept this logic, but I’ve had trouble seeing how to explain it in simple terms.

So rather than try to find a way to explain it i made this picture instead. This shows one dot for each state (except Hawaii and Alaska) plus the District of Columbia. The horizontal axis the the amount of gas tax [see] each state charges. The vertical axis is the price of gas in each state [see].

taxvsgas.png

Oh dear.  This doesn’t seem to be supporting the conventional wisdom.  In fact it seems to say that a gas tax has a disproportionate effect on the retail price.  Every 10 cent increase in the tax is corrolated with a 12 cent rise in the price the consumer pays.  Huh?

My insta-theory for the amplified effect is that the tax rates are higher in states where the cost of doing business is generally higher. For example they have more services, health insurance, employee rights, education, regulation, etc. etc.  As an aside I think it’s interesting that I view a high cost of doing business as a signal that a venue is highly attractive to business; while rhetorically it is often treated as a signal of a bad place to do business.
I must say that I don’t quite see how this chart supports the conventional opinion of the economists.

So, recalling that I think this that lowering the gas tax a very bad idea, my only reason for posting this is to dig into the evidence for the conventional wisdom.  I love the idea that a high tax on petroleum products would largely come out of the producer’s pockets. If that’s true and you can convince a lot of people it should be a easy move toward a better outcome.

Bolt Bus

This is a product endorsement. I wanted to go down to NYC from Boston for a few days, quite spontaneously. So I grabbed a hotel room via priceline at 2:30 in the afternoon; and then I had to find a way to get to down there.

For the past few years there has been an bloom of extremely cheap bus rides to NYC; these run from chinatown to chinatown. The press reports are totally wild-west. Fires, sleeping drivers, gun battles between competitors! But yeah, it’s cheap!

Recently the more established bus companies have decided they need to compete and two new lines have entered the competition. Boltbus and Megabus they both sell a few tickets for a few bucks, i.e. as a teaser rate; but their full fares are cheap too.

So I went downtown and into the bus station and found BoltBus guy sitting in his bus, they leave every hour on the hour. He took my $20 and I climbed in. It would have cheaper if I’d bought the ticket online but it wasn’t clear which one I was going to catch.
Very nice bus, nice drivers, very comfortable smooth fast ride. The trip back was even smoother, taking a little under 4 hours. For both trips the bus was about 30% or less full; so plenty of room to stretch out.

But most importantly free WIFI and a plug! On the trip down a guy behind me drew a crowd as they all watched the Celtics live in the basketball playoffs; via the WIFI.