Tuesday, May 17, 2005


What brought me to Lisp

Since the main emphasis of my writings will be about my explorations in and around Lisp, I thought I'd start with how I came to Lisp. This is an abreviated version of what's here.

A few years back I started looking into functional programming, and started with Haskell, a pure functional language. This is fine for learning the basic concepts of functional programming, but imperative is better for some things, mainly I/O. Haskell's monads made my head hurt. Sometimes you just want to print something out or access a database without getting a PhD.

This led to OCaml, which seemed to have most of what I wanted. Functional, but not obsessively so (you can printf when you want to). Good execution speed. Support for objects. I read a lot of literature about functional programming vs. object-oriented programming and came to the conclusion that both have their uses so I wanted a language that had both. I started writing some simple OCaml programs as I was learning the language and I liked the way they came out, no having to declare variable types, first-class functions, etc. Then I got farther along in my studies, learning more about how objects and classes are used in OCaml. I started looking at how they handled the FP vs. OOP tension, namely adding functions to a existing class/module vs. adding classes and subclasses, and they started talking about parameterized classes and abstract modules and the syntax started getting more and more complicated.

In Common Lisp, the FP/OOP tension is handled with multimethods - much simpler. Metaprogramming in Common Lisp is done with defmacro, backquote and comma and is done in place, where in OCaml you need a separate preprocessor and a syntax that's rather different than the syntax of the language itself.

I would say that OCaml and Lisp give you much the same power to do things, but my experience is that while doing the simple stuff may be simpler in OCaml than in Lisp, doing the complicated stuff is simpler in Lisp than in OCaml, and I plan on doing a lot more of the complicated stuff than the simple stuff.

I don't want to expend my brainpower wrestling with my programming language, I want to expend it solving problems, and with Lisp I don't wrestle the language. Although some say Common Lisp is a 'big' language, it's basically just parentheses and keywords.

If you think the prefix arithmetic is hard, well it can be, but how often do you put the Pythagorean theorem in your code, vs. just making a function call with parameters? Is foo(bar) that much easier than (foo bar)?

Oh, and about the parentheses? Get a parenthesis-matching editor, and get over it.

If you want to use infix expressions in your lisp code, you can. I think there's a macro for it.
Actually I really don't see that much usefulness in warping Lisp into infix syntax. I don't write that much code implementing the Pythagorean theorem, the majority of my code is function calls with parameters. In infix languages this works out to
foo(param1, param2);
while in Lisp it's
(foo param1 param2)
I can live with that.
I am turned to LISP last Friday, when I saw the term prefix notation, which make remember LISP and Genetic Programming.
For interested, here is a page for download LISP for Windows.

Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?