| Practical Common Lisp |
![]() |
| (available as of 9/4/2004 for pre-order). |
The author, Peter Seibel, has posted the book for review and comment on the Web.
Here be the ramblings of a long-time programmer, mostly put here for his personal amusement. If you find amusement here, as well, that's a bonus!
| Practical Common Lisp |
![]() |
| (available as of 9/4/2004 for pre-order). |
.
doSomething(arg1, arg2)
(doSomething arg1 arg2)
Wu [Sheng-Chuan Wu, Franz's Vice President of corporate development] says, "People say 'Java is the gateway to the Internet.' We say 'Java is the gateway to hell.' Lisp is just a better alternative to the intelligent Internet..."
The auther recounts various applications that use Lisp. The closes with this:
Clearly, it's time to take another look at Lisp. And, if anyone thinks that there are no new frontiers that can generate dynasties like Microsoft, just listen to what Bill Gates advised computer science majors at MIT early this year in a question-answer session: 'If you invent a breakthrough in artificial intelligence so machines can learn, that [will be] worth 10 Microsofts.'
If you look at these languages in order, Java, Perl, Python, you notice an interesting pattern. At least, you notice this pattern if you are a Lisp hacker. Each one is progressively more like Lisp. Python copies even features that many Lisp hackers consider to be mistakes.So, why are "modern" languages adopting the features of an "old" language like Lisp? Could it be that Lisp knows something the "new" languages don't?
What I mean is that Lisp was first discovered by John McCarthy in 1958, and popular programming languages are only now catching up with the ideas he developed then....
These excerpts speak to what makes Lisp qualitatively better than other languages. Lisp is different than most other languages: it's self-extending; you can extend the language istelf toward your problem space, making it a more effective tool for solving your problems than a generic language like C/C++, Java or Python....The short explanation of why this 1950s language is not obsolete is that it was not technology but math, and math doesn't get stale. The right thing to compare Lisp to is not 1950s hardware, but, say, the Quicksort algorithm, which was discovered in 1960 and is still the fastest general-purpose sort....
...Lisp looks strange not so much because it has a strange syntax as because it has no syntax; you express programs directly in the parse trees that get built behind the scenes when other languages are parsed, and these trees are made of lists, which are Lisp data structures...
...But the biggest win for languages like Lisp is at the other end of the spectrum, where you need to write sophisticated programs to solve hard problems in the face of fierce competition. A good example is the airline fare search program that ITA Software licenses to Orbitz. These guys entered a market already dominated by two big, entrenched competitors, Travelocity and Expedia, and seem to have just humiliated them technologically.
The core of ITA's application is a 200,000 line Common Lisp program that searches many orders of magnitude more possibilities than their competitors, who apparently are still using mainframe-era programming techniques.
Expressing the language in its own data structures turns out to be a very powerful feature. Ideas 8 and 9 together mean that you can write programs that write programs. That may sound like a bizarre idea, but it's an everyday thing in Lisp.
The most common way to do it is with something called a macro.The term "macro" does not mean in Lisp what it means in other languages. A Lisp macro can be anything from an abbreviation to a compiler for a new language.
If you know OO (or non-OO programming for that matter), you know about abstraction. Abstraction allows you to generalize the logic and features of an application into a hierarchy of layers, where each successively "higher" layer is less language-oriented and more problem/solution oriented. With each layer of abstraction, you move away from the nuts and bolts of writing code, toward defining a "language" of objects that represent your problem space.
Now, imagine that you have at your finger tips a language tool that will allow you to forge a new dialect of that language that is a direct representation of your problem space. This, for me, is the single-most alluring aspect of Lisp: I will be able to describe my problems, and their solutions, using language constructs of my devising that are built in the language I'm using. Sounds recursive, eh?
I don't yet know how to do this, and I only have the barest hint of the implications. However, as the language agnostic practioner that I am, it gives me a little thrill whenever I think about it. Describing problems and solutions at an even higher level than Objects. Cool. Very cool. Even if the language is older than I am.
In another essay, "Beating the Averages," Mr. Graham outlines how he and a partner used Lisp to gain a competitive advantage, trounced their competition and eventually got bought out by Yahoo! -- due in large part to their use of Lisp. Here are some excerpts:In the summer of 1995, my friend Robert Morris and I started a startup called Viaweb. Our plan was to write software that would let end users build online stores. What was novel about this software, at the time, was that it ran on our server, using ordinary Web pages as the interface.A lot of people could have been having this idea at the same time, of course, but as far as I know, Viaweb was the first Web-based application. It seemed such a novel idea to us that we named the company after it: Viaweb, because our software worked via the Web, instead of running on your desktop computer.
Another unusual thing about this software was that it was written primarily in a programming language called Lisp. It was one of the first big end-user applications to be written in Lisp, which up till then had been used mostly in universities and research labs. Lisp gave us a great advantage over competitors using less powerful languages.He quotes Eric Raymond, on becoming a "true hacker," thus:
Lisp is worth learning for the profound enlightenment experience you will have when you finally get it; that experience will make you a better programmer for the rest of your days, even if you never actually use Lisp itself a lot.Mr. Graham then observes that Mr. Raymond's "advice is good," but that it's contradictory. Even though Lisp may be a better language to use, most programmers won't use it.
However, in his Viaweb start-up, Mr. Graham and his partnet chose not to follow the conventional approach:
So you could say that using Lisp was an experiment. Our hypothesis was that if we wrote our software in Lisp, we'd be able to get features done faster than our competitors, and also to do things in our software that they couldn't do. And because Lisp was so high-level, we wouldn't need a big development team, so our costs would be lower. If this were so, we could offer a better product for less money, and still make a profit. We would end up getting all the users, and our competitors would get none, and eventually go out of business. That was what we hoped would happen, anyway.
What were the results of this experiment? Somewhat surprisingly, it worked. We eventually had many competitors, on the order of twenty to thirty of them, but none of their software could compete with ours. We had a wysiwyg online store builder that ran on the server and yet felt like a desktop application. Our competitors had cgi scripts. And we were always far ahead of them in features. Sometimes, in desperation, competitors would try to introduce features that we didn't have. But with Lisp our development cycle was so fast that we could sometimes duplicate a new feature within a day or two of a competitor announcing it in a press release. By the time journalists covering the press release got round to calling us, we would have the new feature too.He then hits on the central reason why, even though any given language may be better than the one you're using today, you won't switch:
What's so great about Lisp? And if Lisp is so great, why doesn't everyone use it? These sound like rhetorical questions, but actually they have straightforward answers. Lisp is so great not because of some magic quality visible only to devotees, but because it is simply the most powerful language available. And the reason everyone doesn't use it is that programming languages are not merely technologies, but habits of mind as well, and nothing changes slower.As further anecdotal evidence of the power of Lisp, Mr. Graham offers this example:
But I think I can give a kind of argument that might be convincing. The source code of the Viaweb editor was probably about 20-25% macros. Macros are harder to write than ordinary Lisp functions, and it's considered to be bad style to use them when they're not necessary. So every macro in that code is there because it has to be. What that means is that at least 20-25% of the code in this program is doing things that you can't easily do in any other language. However skeptical the Blub [a hypothetical language Mr. Graham is using to exemplify other languages - tf] programmer might be about my claims for the mysterious powers of Lisp, this ought to make him curious. We weren't writing this code for our own amusement. We were a tiny startup, programming as hard as we could in order to put technical barriers between us and our competitors.And this is where I find myself: curious about Lisp. Very curious. Curious about macros. Curious about how to write programs formatted as compiler parse trees. Curious about how to write programs that write programs. Curious about that 20-25% of the Viaweb code that couldn't easily be written in any other language.So, I'm looking forward to this journey. I'll keep notes here for any who might be interested. I'll talk about problems, issues, insights and other stuff.
Along the way, Python, Java and Jython may find their way onto these pages. Perhaps editors, utilities or other software we use to write software may find their way here, too.
I've wanted to do something like this for years. And a blog should allow me to do this quite nicely.
See you soon.