Symbols and strings

Does a modern Lisp really need both symbols and strings? In particular, is there any reason to have two separate types, and reader syntax for both?

Traditionally strings have been mutable (even literals!), and symbols have had properties other than their names, so it has been easy to justify having separate types. But a modern Lisp may reasonably have immutable strings, and remove all extraneous features from symbols, so the only difference is whether they're interned. That's not worth making a distinction of type.

There's a practical problem: when they appear in source code, "foo" is written for its characters and foo for its identity. So "foo" needs to be self-evaluating, unlike foo. Does this mean they have to be different types?

No: " can be a reader macro, so "ice cream" reads as '|ice cream|. That interferes with its other uses, like docstrings, but not badly. (And it's about time we replaced docstrings with something a little more flexible, anyway.) Maclisp used '|explicit quoted symbols| wherever strings were needed, and it was annoying to read, so we do need the abbreviation.

While we're messing with ", let's make it read as something distinctive: (doublequote foo) instead of (quote foo). This has two good properties which every reader macro should have. First, it's reversible, so read and write can remain inverses as far as possible. Second, it's a simple abbreviation, so it preserves the transparency of syntax, and avoids entangling the reader with other parts of the language. It's also more flexible, because we can change its meaning by redefining doublequote. This makes it easy to add features like string interpolation, where "Hello, $scope!" expands to something like (format nil '|Hello, ~A!| scope). And this can all be done in user code, without complicating the language kernel.

I think I won't miss strings.

Chris Okasaki has a blog and booleans

Chris Okasaki (he of the heroic efforts to analyze performance of partly-lazy data structures) has a blog now. It's pretty good, and readable.

I like the post on confusion over boolean expressions. (But comparisons are distinct from booleans in most machine languages...) I know I have been guilty of excessively explicit logic, usually in the misguided service of clarity. The other day I found an example in some code I had written a few months ago: if (match && !desired || !match && desired). I didn't understand it until I verified that it was equivalent to if (match != desired), which I had avoided on the grounds that it was confusing. I guess I was wrong.

You know you've been using zero-based indices too long when...

I was reading about population genetics of unusual sex ratios and encountered this bit:

Then the fitness of the second organism is proportional to:

x /( x + x0 ) [ ( 1 - x ) + ( 1 - x0 ) ] + ( 1 - x )

Where x is the sex ratio produced by organism #2 and x0 is the sex ratio of organism #1.

Confused by the variable names, I mentally corrected x to x1:

Where x1 is the sex ratio produced by organism #2 and x0 is the sex ratio of organism #1.

One for the second organism and zero for the first? This seemed perfectly intuitive and unconfusing to me, because it's so familiar. Only when I tried to put it into words did I see the problem. Numbering from zero breaks the correspondence of cardinal to ordinal numbers, so speaking of it means fighting natural language with every word. It may be mathematically natural, and sometimes more convenient (and sometimes less), but I still prefer one-based indexing.

Clones for comparison

There is one reason to clone example programs: they're nice for comparing languages. As long as they're short enough to read quickly, they're a nice way to show how a language differs from others. As long as it's not too different, anyway - if the examples aren't expressed in much the same way, they won't map onto each other easily, and the reader will learn nothing except that the language is really weird.

I've used the Shootout programs as comparative examples occasionally, since they're available in so many languages that there's usually one close enough to compare to. I also use them to test the expressiveness of my languages. They're simple and easy, yet well-defined, so I can't reinterpret the problem to match whatever's easy in my language. Unfortunately I haven't found a solution to the inverse problem: I am tempted to revise minor details of my language to fit the problem. Done generically, this is good, but done for a specific problem, it destroys the value of the test, and does nothing to improve the language.

It does produce some impressive expressiveness results, though. When you even minutely customize the language to the problem, it's not hard to make it shorter and clearer than Perl and Haskell, for a wide range of problems. Now if I could just figure out how to do that in general...

Enough APL hate!

Ron Garret, while talking about something else, brings up APL for a fashionable slander:

But the drawback to APL is so immediately evident that the mere mention of the language is usually enough to refute the extreme version of the short-is-better argument: APL programs are completely inscrutable, and hence unmaintainable.

I don't mean to pick on Ron especially - a lot of people repeat this, because it's easy and satisfying, even when they know better. Ron evidently does, as he says a few paragraphs later:

Most people find APL code inscrutable, but not APL programmers. Text from *any* language, programming or otherwise, is inscrutable until you know the language.

So why the reputation? APL's one-character names give it an opaque surface, but there's nothing difficult there. Once you learn the names (and there are only a few dozen), there's no more mystery. If this were all there were to APL, the mysterious hieroglyphs would correspond to familiar concepts, and would be easy to learn. But there is something else going on: APL is a functional language.

Despite its prominent assignment operator, APL has very few side-effecting operations. Its programs are usually in a functional style, and are therefore much shorter than their imperative equivalents. To a reader who doesn't expect functional code, this completely obfuscates them, and makes it impossible to find a correspondence between the mysterious operators and familiar concepts. In addition, there are two features that further shorten programs:

1. map is implicit. Values are arrays, and scalar operations (e.g. +) are mapped across arrays without any need to say so. Together with a large supply of predefined array operations (with one-character names!), this makes a heavily collection-based style practical.

2. There are several high-order operators. / is reduce; \ is scanl; . is a combination of Cartesian product and map. As it turns out, high-order operators are especially handy when they have short names and high precedence. (APL's successor, J, takes high-order support even further: it supports some points-free function definitions.)

Here's the real reason I'm talking about APL: both of these features are easily adaptable to other languages. You can get a considerable amount of implicit map just by adding methods to the arithmetic primitives. Libraries of collection operations are even easier. I suspect that if you add these features to a language, you can get much of APL's brevity, even without syntax or inscrutably short names.

And APL may even begin to look less mysterious.

By the way, Ron also said:

a web server in APL would probably be an awful lot of work

Googling... it appears to have been done, but not in public. But I doubt it's especially long. APL can do most of the same things other languages do, so while it might look verbose to an APLer, I doubt it would be longer than in imperative languages.

A plea for original examples

Language designers: when you write sample programs to show off your language, please don't clone existing programs. Clones demonstrate that your language can do the same things other languages can do, but so what? The world doesn't need more programs whose only virtue is the language they're implemented in. We already have Tetris and Minesweeper and a zillion web servers. The world especially doesn't need more implementations of Emacs. Yes, it could have a better extension language, but Emacs' strength is the corpus of elisp that people have written, and your clone will not have that. So don't waste your time.

Instead, go directly to the good stuff. Think of how often you have cool ideas that you'd like to implement, but don't because you think it's too difficult. Make these your example programs, and judge your language on its ability to make them easy. That's what it's for, right?

As a language designer and as a programmer, your hope of notoriety rests on creating something new, something that isn't already available. It's easy to follow someone else's example, but the result will not inspire anyone else. There is no language-promotion tool like a killer application. Try to write one.

Experience with vapor

Lispjobs says:

Arc developer, seven+ years experience required.

How ordinary. :)

(Via Planet Lisp.)