Functionally wrong
I keep hearing people say that Lisp is (primarily) a functional language. It isn’t. Lisp isn’t a language at all. It’s like saying that C++, Java, C#, JavaScript and so on are all C because they have C-like syntax. In many ways, JavaScript is more like Lisp (with C-like syntax) than it is like C. It is not C, or even a dialect of C.
At present, there are two main languages with Lisp syntax: Scheme and Common Lisp. Scheme was designed as a functional language, but Common Lisp was not. It was a language designed by committee in the ’80s, based on the different but similar products of a number of vendors. As such, it contains a lot of ideas that, back in the ’80s, I thought were good, too, but now I think violate good programming practice (encapsulation, for example) and shouldn’t be used in real projects.
It also contains a lot of good ideas I wish we had in languages like Java. And some that are just plain overkill (like the CLOS MOP – Common Lisp Object System, Meta-Object Protocol) and I doubt are ever used (but I could be wrong). Worth looking at, if you are interested in language design.
You can certainly write Common Lisp programs in a functional style, and sometimes I do. You can also write in a logic-programming (prolog) style, using a technique called continuation passing. I’ve done that, too. But I usually write code in the familiar procedural style. Nothing wrong with that; most real programs (thousands of lines of code), even in Commons Lisp, are/were written procedurally.
It’s worth learning the functional style and using it if you like, but don’t make a religion of it. There’s nothing wrong with using setq in Common Lisp. (I don’t, though – I use setf!)
But it’s not functional programming that makes Lisp interesting – you can do it in many modern languages. Other things, such as ‘program as data’, which makes it easy to extend the language, are far more interesting.
Jonathan Cunningham
Neil says…
I’m not going to disagree with you, but it sounds like we might be splitting hairs on definitions – sure, Common Lisp is a dialect of Lisp. Mike was writing about Lisp as a classic language from a historical point of view, rather than teaching functional programming or, indeed, Lisp. We have looked at functional programming in the past, when Mihalis Tsoukalos looked at Haskell (see LXF201, LF197), but Mihalis is a computer science expert, so is better suited to tackling that type of topic.