Archive for June 3, 2003

Tuesday, June 3, 2003

Infinity

Someone at kuro5hin has written an exceptionally clear article about infinity and countably infinite sets.

F-Script 1.2.4

F-Script 1.2.4 is out.

Dynamic Scoping

Most sane individuals know that dynamic scoping is evil. However, it can be useful, and Dave Thomas shows that when made explicit it can actually be pretty nice. His code demonstrates some powerful Ruby features: using blocks to add syntax to the language and (ab)using callcc. Neither of these is possible in Python.

The way his first implementation works is that find_in_context throws an exception that’s caught in with_context. The exception stores a function that knows (a) the name being looked up, and (b) find_in_context’s continuation. with_context passes the function its context. If the context contains a binding for the name, the function calls the continuation with that value. This makes find_in_context return the value to its caller. The use of continuations is totally gratuitous, as Thomas later shows.

Food for thought: since exception handlers are themselves dynamically scoped, this implementation is, in a sense, circular.

Multimethods

Dan Sugalski does a great job of explaining multimethods. And there’s more:

Haskell, for example, allows you to dispatch based on the values that are passed, as well as their types. This is a tremendously powerful mechanism, though one that’s not often implemented. (I have a nagging suspicion that’s as much because it becomes close to impossible to mathematically prove a program's correctness with this scheme as the cost, and the folks doing language research tend to be of a theoretical bent. I may be wrong, though)

I worked on a language that had where clauses, a slight generalization of his example. You could say stuff say foo(a, b : Int) where a ~= b/2 or foo(e : E, l : Seq[E]) where e = head(l). The language was designed with theorem proving in mind. However, this does complicate some things. And what do you do if the where clauses of the different methods aren’t disjoint?

Two more points:

Cocoa AppleScripting

Buzz Andersen:

Read any article about AppleScript and Cocoa (see Andrew Stone’s tutorial for example), and chances are you’ll be told right off the bat how easy it is, thanks to the wonders of key-value coding, to add AppleScript support to a properly designed application. What these experts might have forgotten, however, is that they’re right about it being easy—but only after you understand how to properly manipulate a bunch of fairly confusing XML!

Fortunately, there is Suite Modeler, which is much better than editing XML by hand. Unfortunately, it seems to be designed for screens the width of the Cinema Display and always leaves its daemon running.

The Danger of Databases

Victor Ng:

Having everything in an object database is cool until you start using it. Then you realize that you’ve lost all your existing toolchain to manipulate data on a UNIX box. grep? sed? find? All gone. vim? haha good luck.

This is essentially the other side of the Power of Plain Text. Of course, this is not to say that everything should be plain text, just that there are tradeoffs. Funny (perhaps) story: a while ago I was designing a format for serialized objects. Efficiency wasn’t the primary concern, so I picked sexps. We already had code to generate and parse them, and they could easily be manipulated with Emacs and diff’d by the regression tests. I started pitching this using my (I guess) Mac vocabulary of text files vs. binary files. Josh’s first comment: text files are binary, too.

XML Namespaces

Keith Devens says that namespaces don’t solve a real problem:

Well, if a computer can’t divine what to do with a piece of XML without having code written by a human process it—the human’s mind is the only place where the “meaning” of the XML can be said to be known, not in some “schema”—then what does the namespace give us (besides a headache)? I say nothing.

I’m just sick of everybody trying to write some labels down (that’s all an XML document is) and claim that it has some “meaning” apart from a mind understanding it.

Cortland Reloaded

The Mac Wars continue with Terry sporting a Neo-style trenchcoat.

Python 2.3 Method Resolution Order

Michele Simionato describes the, uh, the above.