Sunday, March 25, 2007

Hobbling scheme for readability?

There's a discussion going on over at Lambda the Ultimate about the use of Scheme as a shell scripting language (scsh). As is typical in such discussions, the people accustomed to parentheses are saying that all the parentheses aren't so bad, while the people unaccustomed to them feel that traditional shell scripting is clearer.

I gotta come down firmly on the no-parens side of this debate. Lispy parentheses are an egregious example of center embedding, which are an impossible strain on short-term memory. It's quite hard to write lisp code without help from an editor program that counts parentheses for you. Lisp is optimized for machine parsing, but pessimized for human parsing.

It would be interesting to see just what limits there are on programs you can write without center embedding. Suppose you had a dialect of lisp in which the outermost expression did not need parentheses around it, a comma would close a single paren, a period would close multiple parens, and whenever there are two levels of paren, the ONLY way to close them would be with a period, which would end the outermost expression. So something like this would be legal:

a (b c, d (e f, (g (h (i j.

and would look like this in traditional syntax:

(a (b c) d (e f) (g (h (i j))))

The point being that you could nest as deeply as you liked, but only at the end of the expression. I don't know, it looks kind of ugly at first glance, but it parallels nicely English structures like:

This is the cat that ate the rat that lived in the house that Jack built.

If you forced yourself to write in that style, and just defined variables to refer to when you couldn't find a way to structure things in this way, I wonder what the program would look like.


Evan Root said...

"parallels nicely" is a stretch. The Center Embedding Wikipedia page details how no serious language does center embedding even though The House That Jack Built is perfectly grammatical. The House That Jack Built is essentially the only example in all of english were center embedding is used more than 3 deep and it is perhaps only famous because it explains this otherwise inferior speech pattern.

Chris Bogart said...

The house that jack built is not an example of center embedding; it's right-embedded. A center-embedded sentence would pop back out at each level like the example the Wikipedia article gives: "A man that a woman that a child that a bird that I heard saw knows loves". The house that Jack built sentence is easy to understand; the center-embedded Wikipedia example is hard to understand.