Content from 2017-12

Learning Common Lisp in 2017 Part 1: Getting started

posted on 2017-12-11 8:30:00 PM

Introduction

Welcome to the first of hopefully many posts on providing a basic overview of the wonder language that is Common Lisp. Many folks over the years have provided many different versions of this talk (I will provide a few tutorials and book suggestions at the end of this post). However, one thing that is often ignored is how to actually setup a Common Lisp Development Environment. While the approach I have personally documented here may not be what others have suggested, since over time development environment and practices have changed amongst other reasons, it is the fastest way to get up and running so that we can concentrate on learning and writing actual CL code versus quitting after finding it difficult to get setup to begin learning.

Purposes of Setting up Environment First vs using REPL

One question that is often brought up when learning Common Lisp is the reason why we set up a development environment ahead of time? Why not first learn the language and then start writing code directly in the REPL? When I first started learning Lisp back in 2006 (and I was a bit naive back then and was unaware of SLIME), I took this approach while reading Practical Common Lisp (one of my first suggestions to learn Lisp, more on this later). However, I quickly realized, a few things: - As one does more scripting, at some point it becomes very useful to just pop up an editor and actually save your work to a file. - Most REPLs don't have readline commands built-in (at least the REPLs I've used never had read-line built-in).

For those of you aren't familiar, Readline is a library that gives nice emacs-style keybindings to applications. One of the features which I have often have used that is with this library is history (a nice way to look up commands and code previously executed).

There are other reasons, of course, why you should use a dev environment, but these are just from learning perspective.

Common Lisp was one of the first languages to have what we now called an Integrated Development Environment or IDE. Many of the features that were provided by the Lisp machines and dev environments like Interlisp-D were incorporated into modern IDEs for other programming languages like C++, Java, and so on. However, the introspection facilities of these IDEs still leave something to be desired, but I am getting ahead of myself since this is an introductory talk :-) So let's begin.

Roswell : A CL environment setup Utility

There are many barriers a newcomer to Common Lisp hits as he is first setting up and getting up to speed. Things like:

  • which Common Lisp should I use? SBCL? CCL? Allegro? etc?
  • how do I setup a SLIME environment to use this Lisp?
  • how about Quicklisp?
  • ...

The list goes on... The solution to these needs has been released as a recent development, and that solution is Roswell. Roswell, as the site goes provides a nice tool to help manage different Common Lisp implementations, as well as unified way to test, build and distribute CL applications. There are many features in Roswell, and I will expand on Roswell in later posts, but first I would like to show how simple it is to get up and running with Common Lisp and SLIME with Roswell.

Pre-requisites

First we must download and install a few pre-requisites before we begin:

  • Download and install Roswell for your platform.
  • Download and install Emacs for your platform

Setting up your environment

When you first install Roswell, all one has to do is run the command:

? ros setup

and Roswell will download SBCL (Steel Bank Common Lisp) and set it up with Quicklisp. To test this all works, all you have to do is run:

? ros run

and you'll see a SBCL prompt indicating it has been installed. run (quit) and the shell to exit. Next we will install SLIME by running:

? ros emacs

This command will simply install SLIME using quicklisp (if it isn't already downloaded) and then it will actually open up emacs with a SLIME buffer available so you can get started writing lisp code. However, if this is your first installing SLIME with Roswell, you may end up having to first exit Emacs and add the following line (which is Of course can exit the SLIME buffer by type M-x slime-quit-lisp if you want, and then exit Emacs using C-x C-c. At this point, though, you are all setup to begin your lisp journey.

Book Recommendations

At this point, you are ready to begin your Common Lisp journey. A couple of suggestions on books that you can read to get you up and running include:

  • Practical Common Lisp: Great introduction to Common Lisp. This book is available in its entirety online, but also can be purchased in paper form from Apress.
  • Land of Lisp: This book introduces to Common Lisp in the guise of writing small games in it. Very fun to read and learn CL with. However, I still think Practical Common Lisp gives a better overview of the language for enterprise type projects as well more larger scale projects. Nevertheless, this book is sttill worth reading, if anything to write some opengl in CL :-)
  • ANSI Common Lisp : This book, while older than Practical Common Lisp is still a very useful reference for programming ANSI Common Lisp as it is documented in the standard. It also has a good introduction to Macros.
  • Common Lisp Recipes: This a good collection of practical patterns that will help you write modern common lisp code and will help you get up to speed quickly on issues that you will encounter as you learn to program Common Lisp in the large.

The books mentioned here cover the language fairly well and introduces all the basic aspects to day-to-day development in the program. Advanced topics like CLOS, Macros, and the Metaobject Protocol are introduced and covered in books like:

  • On Lisp
  • Let over Lambda
  • Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp
  • The Art of the MetaObject Protocol

Video selections

On top of the above book suggestions, I would also recommend Bagger's Little Bits of Lisp series located on Youtube. It is a small series of introductory Common Lisp videos and covers various topics, but not everything that are covered in the books. I would suggest to consider more as supplementary material to watch as you go on your journey to learning the language.

Until Next Time...

That's all for now. In the next installment, I will speak more about Roswell's features as well as using it to write shell scripts in Common Lisp as well as create executables.

This blog covers blogging, coleslaw, common lisp, lisp

View content from 2017-12, 2017-07


Unless otherwise credited all material Creative Commons License by lambdajunkie