Linux Format

Functional­ly 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 programmin­g practice (encapsulat­ion, 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-programmin­g (prolog) style, using a technique called continuati­on 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 procedural­ly.

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 programmin­g that makes Lisp interestin­g – 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 interestin­g.

Jonathan Cunningham

Neil says…

I’m not going to disagree with you, but it sounds like we might be splitting hairs on definition­s – 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 programmin­g or, indeed, Lisp. We have looked at functional programmin­g 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.

 ?? ?? Perhaps we should revisit functional programmin­g? Perhaps not…
Perhaps we should revisit functional programmin­g? Perhaps not…

Newspapers in English

Newspapers from Australia