Saturday, October 20, 2007

Lisp is alien. Cool!

On hearing a statement that anything in a Lisp program is recursive (which I though was an exaggeration), I opened up its respective Wikipedia page and started reading.

The article is merely meant as an overall introduction to the language (just as I expected), and that's pretty much what I got. What I was left with upon finishing the article was that Lisp is all about lists - all the examples involve them, although they do say in one place that
Because conses and lists are so universal in Lisp systems, it is a common misconception that they are Lisp's only data structures. In fact, all but the most simplistic Lisps have other data structures – such as vectors (arrays), hash tables, structures, and so forth.
I assume therefore that when you want arrays, or other data structures, you write them as lists too. Strange.

Here's something interesting I found out on the same page:
The now-ubiquitous if-then-else structure, now taken for granted as an essential element of any programming language, was invented by McCarthy for use in Lisp, where it saw its first appearance in a more general form (the cond structure). It was inherited by Algol, which popularized it.

Now, for someone coming from such programming languages as Java, ActionScript, or C (which they all inherit, to some extent), a lisp program is hideously difficult to read.
I suppose I should learn Lisp, but it seems so foreign. (Paul Graham, '83)

You've read my mind there, Paul. However, it's all the more incentive for me to learn it. But not just now, I'm still tinkering with Java (I'm learning it in paralell to ActionScript development). I wonder how long it takes to get used to reading Lisp. I mean, there were some examples spanning 4 lines and they took me the equivalent of a 50 lines class in any of the above languages. In any case, I'm almost positive (although it's more of a hunch than a documented certainty) that Lisp is more difficult to read through than Java, for instance, for equally advanced programmers in the respective languages. But it seems that it's also shorter, so there's a chance that the overall lecture of a source code might be shorter for Lisp. I wonder...

I might get some answers from Paul Graham's articles - I've seen he has one where he compares Lisp to other major programming languages, which must be an interesting lecture.

In any case, the article got me interested. It is so different from anything I've wrote code in that I'm attracted to it - it might be similar to going back to the point where people invented the wheel and then inventing something else, completely different, paradigim-wise. It might be a good chance to expand my programming horizons and simply to try something totally new.

As for my recursion issue, the answer is that not everything in Lisp is recursive:
Programmers in the Scheme dialect often express loops using tail recursion. Scheme's commonality in academic computer science has led some students to believe that tail recursion is the only, or the most common, way to write iterations in Lisp; this is incorrect. All frequently-seen Lisp dialects have imperative-style iteration constructs, from Scheme's do loop to Common Lisp's complex loop expressions.
[...]
Lisp syntax lends itself naturally to recursion.

No comments: