Learning Common Lisp 

Common Lisp is an old language compared to many that are used now, such as Java, Python and C#. But this does not in any way mean it is no-longer useful, in fact it has many of the features that many modern languages have and many that they don’t. One of the great things about lisp is that if it does not have a feature that you would like it to have you can add it yourself.

While many programming languages we use today have a standard that sets out how things are done or a single implementation, Lisp is a little different as Lisp is the name for a family of dialects all of which do things slightly differently and have different focuses. Common lisp is one of those dialects there is also scheme which is a simplified version of lisp and Clojoure as well as many others. There are also differences between the implementations of each lisp as while there is a set of features that all lisp implementations must provide they can also provide some specific to that implementation of lisp.

Because lisp grew up in the world of artificial intelligence research at a time when computers had a fraction of the power that they have today, lisp has become a language that uses resources very efficiently and can come close to the speed of C if required. Unfortunately its use in artificial intelligence research likely gave it a reputation that was one of the factors that lead to its decreased usage over the years.

Another useful feature that lisp has is it’s REPL (read eval print loop) which allows you to evaluate segments of code as you are writing it. This is similar to what can be seen in languages such as python (although you may not have used it) and is used a lot when developing lisp applications. The REPL will allow you to define and redefine functions as well as test them before integrating them into the rest of your code.

While Common Lisp does have many things that make it a great language to use there are a few things that could act as a barrier to learning it. These result from the fact that for a period of time lisp was only used by a small number of people. Because of this less work was being done on tools that could be used with lisp, but as lisp is beginning be used by more programmers this is slowly changing and thanks to what is referred to as the foreign function interface (which allows lisp to be used with code written in C), this means many popular API’s such as OpenGL and gtk can also be used with Common Lisp.

If you were to look at a few lines of common lisp code which you likely have already you would have notice what some may call an excessive use of parenthesises. Where languages such as C and C++ use “{} ” and “;” to indicate blocks of code common lisp uses “()” (this is where having an IDE that automatically adds the “)” for you becomes very useful, you may also want to take a look at an earlier post on swapping the numbers and symbols on your keyboard). Another way of thinking about common lisp code is that everything is a function call, as an example of what I mean I will show a comparison between two code samples.

C++ 

if (foo == bar)
{
//some code here
{

Common lisp 

(if (equal foo bar)
;;some code here)

you can think of equal as a function where “foo” and “bar” were passed in as arguments, if you can think of lisp code this way it will make it a little less daunting when you attempt to learn it.

If you have made it this far and still want to learn common lisp then below are a few things to help you get started. First you will require an IDE to use, but as lisp is not widely used there is not much to choose from. At the moment there are some commercial options available but many start with Emacs with the slime extension. Using Emacs and slime is relatively straight forward and there are plenty of resources on the internet to help you get started. You may also want to look into installing quicklisp which is a package manager for lisp that allows you to easily download lisp packages to use in your own applications. You will also need to install a lisp implementation, while there are many available sbcl is a popular choice.

Once you have slime and Emacs working you will be wanting to find some learning resources so that you can start writing lisp code. As common lisp has been around for a while there are many books available many of them written years ago, although that does not mean that they are not useful. Also note that when looking for books you want to make sure that the book is about common lisp as there are other dialects of lisp that do things a little differently. The best book I have come across is Practical Common Lisp which is available online for free. You may also want to take a look at cliki.net and common-lisp.net which have various resources that will aid you when using common lisp.

All that is left is for you to follow some of the links above and discover how good common lisp is for yourself.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s