Why Lisp is Awesome

A few weeks ago, I was talking to some people about the nerdy things I work on, and the nerdy things I like. The conversation inevitably turned to Emacs and Lisp, and someone asked why I liked them so much.

There are a lot of reasons, but I think the main one is that it’s such a pioneering and influential language, and most people aren’t aware of it. An astonishing number of language features we take for granted owe their existence to Lisp.

So there you have a short tour of what’s cool about Lisp, and the features you’re using that you owe to it. Not all of these features were in the earliest version of Lisp, but it’s quite a feat that so many advanced high-level language features first appeared there. The original paper on Lisp is still quite relevant, and shows some of the algorithms you can implement with the earliest parts of the language.

I don’t mean to bash on C here; I actually really like C for what it is. And it’s not unlike Lisp in that it’s a highly influential language with an extremely simple core.

What’s fascinating to me about Lisp is that a language which is fifty years old is was so advanced, and is still so influential. In the fast-moving world of computing, that’s truly an amazing accomplishment.

2009/01/10
Previously On Atomized:

Discussion

you can short-circuit in C:

int main () { printf(“%d”, (0 || 1)) }

bob
2009/01/11

I’m not sure if you know, but Lisp has a “case” macro (http://www.lispworks.com/documentation/HyperSpec/Body/m_case_.htm) that basically has the same functionality as C’s switch, if that’s what you want.

Also, the results of destructively modifying a list created with quote (as you did in your ‘references’ example) are undefined (see http://www.lispworks.com/documentation/HyperSpec/Body/s_quote.htm#quote). Depending on what exactly you do it, and the internals of your lisp implementation, it may work – but it isn’t portable.

Otherwise, this was a very interesting post.

Shaneal Manek
2009/01/11

I just realized your code was Emacs Lisp, not Common Lisp (the fset and setcar should have given it away). Sorry, carry on as you were. I basically only code Common Lisp (just a few lines of Emacs Lisp in my .emacs), and seeing s-expressions automatically puts my brain in CL mode. I have a hell of a time trying to code Scheme ;-)

Shaneal Manek
2009/01/11

@bob, are you sure about that? Compiling that code gives the warning “passing argument 2 of ’sprintf’ makes pointer from integer without a cast,” and running the resulting binary produces a bus error.

Doing `0 || 1′ in C will work in some places, for sure, but what doesn’t work is `0 || x’ – you will get a TRUE, rather than the value of x.

Ian
2009/01/11

This kind of things make me feel very sad about the fact that GNOME was originally intended to be developed in Scheme…

At least sawfish was returned from dead some months ago (http://sawfish.wikia.com/)

Ferk
2009/01/11

Use Haskell, It is a more powerful language and a pure Functional Programming. Ocaml and F# are awesome too. The problem of Lisp for me is that it feels already old the language and the S expression is a feature but sometimes is a pain in the neck..

OtengiM
2009/01/11

This is simply not true:

>In lisp, you can test for any condition, whereas C only lets you test one expression.

Try the following in c, c++ or php:

switch (true) {

case (foo === bar):
echo “identical”;
break;

case (i=3):

break;
}

Andreas
2009/01/26

C sucks even more:

switch (var) {
case “foo”:

will test not for string but for pointer equality. In most cases, this code will be severely buggy.

Nightfly
2009/08/21

In Scheme there’s a special case construct that mimics switch even more concisely:

(case
((“foo”)
(message “This is the foo block.”))
((“bar”)
(message “This is the bar block.”))
(else
(message “Default case”)))

Matt Might
2010/01/06

switch-case is not equivalent to if-if-if-if…

switch can only match the value of a variable with expressions (case : … ) that are available at compile time.
The vantage is that “switch” can be compiled (and infact, it is) with an hash-map that in O(1) points directly to the correct “case” piece of code.

(cond
((= var “1″)
(message “This is the foo block.”))
((= var “2″)
(message “This is the bar block.”))
….
((=var “10000″)
(message “…”))

always takes 10000 run-time operations, while

switch(var) { case 1: … case: 2 … …. case 100000: …. }

always takes O(1).

Claudio Santini
2010/01/06

I’m sorry, but you know neither Lisp nor C!

Nothing you present as an advantage of Lisp is essential to it (or even unique), and you don’t discuss what actually distinguishes it (regular syntax, and thus macros). Your C switch example is simply wrong!

Fred
2010/01/06

C now has lambdas, called “Blocks”. Late to the game, but great to see. Thanks Apple!

http://en.wikipedia.org/wiki/Blocks_(C_language_extension)

Joshua Kifer
2010/01/07

Participate