Getting open for new paradigms

I think that all you five readers (ok, I’m being too generous) of my blog know that I love Ruby. Well, I’ll tell you why I haven’t posted in awhile: I have met someone new, and now Ruby only feels… well, it is still pretty good, it just is hiding even better stuff from me.

Yes, that’s right. I’m learning that old-fashioned, parenthesis-filled, known as crappy language called Common Lisp. And… well, parenthesis is a silly reason for you to not learn it, too.

I tried to make a long post explaining why the language is good, but it would require a book. So, instead, I’ll post a link to Practical Common Lisp and tell some things that may convince you:

Ruby’s internal object system is based on Emacs Lisp’s object system. Emacs Lisp’s object system is based on CLOS (Common Lisp Object System).

So imagine all the power of Ruby’s internal typing and message passing (which in Common Lisp is actually message dispatching, and for good reasons), but exposed to you, everything modifiable.

Code is data. Data is code.

Everything in Lisp is composed by S-Expressions, which is simply a syntax for linked lists. And the language has lots of functions to manipulate linked lists. Yes. Yes, you can manipulate your code with these concepts.

First-class functions and lambdas are more flexible than Ruby’s blocks.

You can easily have more than one function as a parameter on Lisp. You can pass a function as a block more easily. For instance, compare this:

[3, 1, 2].sort { |x,y| y <=> x }

With this:

(sort '(3 1 2) #'>)

In the second case, you’re passing the “>” (higher than) function directly to the sort function. On the case of sort it may not be much, but see how you multiply all the elements on your array:

(reduce #'* '(3 1 2))

What if I need to pass a custom function? Well, use a lambda:

(sort '("a" "def" "bc") (lambda (x y) (< (length x) (length y))))

And if I’m creating a function that receives another function? Ruby has yield, is Common Lisp as easy?

Yes. Funcall:

(funcall <variable storing the function> <arguments>)

It can be interpreted, but it can also be compiled.

You can compile Common Lisp code to native code and run it with a great speed, unlike Ruby, which needs to be interpreted or to run under a virtual machine. And yet, you have the facilities of an interpreted language, as garbage collection, on the fly evaluation, first class functions and closures.

Common Lisp isn’t functional, as some people may seem to think.

As I’ve said before, Common Lisp has a powerful object system. It may give support for imperative style programming and declarative style programming. Most lispers seem to have some preference for functional and declarative programming, because it’s often shorter and more trustful. So, don’t be afraid of Common Lisp because of something like programming paradigm: it will fill your needs.

If you complain about lack of libraries, you shouldn’t have started to use Ruby in the first place.

Using something only because it’s popular leads to average technology, not better technology.

I mean, Ruby is good. But you should try Common Lisp yourself and see if it’s better.

If parenthesis bother you, try a good editor, most of them have great navigation for it.