Thinking in Clojure vs Common Lisp

Whatever is on your mind, whether Lisp related or not.

Thinking in Clojure vs Common Lisp

Postby billy » Wed Apr 29, 2009 4:45 pm

Hi, I'm relatively new to the Lisp world aside from hacking on my .emacs.

I'm reading through my beta copy of Programming Clojure, and there seems to be more of focus on creating lazy sequences as opposed to recursive functions (mostly because of the lack of tail call optimization in the JVM).

I was wondering if someone could compare that to thinking in Common Lisp. Does CL have lazy sequences? If so, is this the preferred way to structure your program?

I'm know I want to use Lisp for a web app project I'm working on, I'm just trying to decide between the two. I kinda assumed that there was just some syntactical differences between the Lisp dialects, now I'm seeing that the differences may extend much further.

Posts: 8
Joined: Fri Apr 24, 2009 11:56 am

Re: Thinking in Clojure vs Common Lisp

Postby ramarren » Thu Apr 30, 2009 3:02 am

The usual way to structure a program in Common Lisp is to use neither recursion nor lazy sequences, but stateful iteration. There is a number of libraries giving lazy sequences or similar, for example series, but they are rarely used. Recursion is relatively more common, but CL standard doesn't guarantee tail call optimization.
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland

Re: Thinking in Clojure vs Common Lisp

Postby Paul Donnelly » Thu Apr 30, 2009 1:32 pm

Thinking in Common Lisp is deciding what you want to do, then doing it. If lazy sequences are that thing, then go right ahead. This isn't Python, where there's one true way to write your code. Most Lispers would turn to something else first, but having the flexibility to do as you think best is the whole point of writing in Lisp.
Paul Donnelly
Posts: 148
Joined: Wed Jul 30, 2008 11:26 pm

Re: Thinking in Clojure vs Common Lisp

Postby Unne » Sun May 03, 2009 3:44 pm

There's nothing wrong with using recursion in Clojure. Use loop + recur, it works fine 99% of the time. I very rarely find myself using loop + recur though; they are more low-level than you usually need. map, reduce, filter, for (list comprehensions) and friends are better.

Stateful iteration in Clojure doesn't make sense because the data structures you're (usually) working with are immutable. You should instead be taking some structure and producing a new structure based on it (which is why map and friends fit well). The immutable data structures are the main place you have to change your thinking in my opinion; once you get used to those, everything else clicks into place.

Laziness can be safely ignored or taken for granted most of the time (but keep in mind that it's going on, so you know when to force evaluation via dorun/doall for example). The Programming Clojure book does go a lot into lazy sequences but I think they only really make sense for certain kinds of problems, e.g. dealing with infinite lists and such.

Having written a web app in Clojure and Common Lisp, I personally prefer Clojure, but both work fine. Compojure is fun.
Posts: 32
Joined: Sat Jun 28, 2008 6:10 pm
Location: Oregon

Return to The Lounge

Who is online

Users browsing this forum: No registered users and 3 guests