I was reading on Lisp as a development for a very long time (Paul Graham’s writing definitely played a factor, and also a couple of other things). I even did start on Land of Lisp but never could finish it, and Lisp fell off the radar.
I wanted to get back to this (more later) and had to setup a dev environment that would help me learn more. Even though clisp was an option, I didn’t want to rely on gedit and clisp on the command line. That didn’t feel right.
So, here is the account of how I went about setting up Lisp on a Linux Mint (Ubuntu would do just fine). If you are looking for instructions for Windows, most of these might work – YMMV.
- Based on this discussion on SO, I decided to use the ClozureCL. Even though SBCL and ClzureCL seem to be able to generate native binaries, I thought that the native support of threads is something that will be helpful in the longer run. Ideally though, it would have been nicer if there is no difference between the various LISP flavors
- The next step was to download the CCL on the Linux machine. Again, I preferred setting up everything on a Linux machine, just to avoid myself the pain of getting things working. The main idea is to write the Lisp code, not worry about the setup (though the latter took a lot of time too)
- Download the CCL from Clozure FTP – got the 64bit version, since I was running a Linux Mint Nadia distro on a laptop and Linux Mint Maya on a VM.
- The installation required unzipping the file and that was very simple. Another change I did was to the
$CCLDIR/scripts/ccl and $CCLDIR/scripts/ccl64files, providing the directory for the
- Now this was the CCL setup and the next thing was – well, setting up the IDE. After a searching for a while, realized that the best suggested IDE seemed to be emacs. I have been trying to get my head around emacs (have been a intermediate vim user for a while, though haven’t done much for a while now). So, I thought, well, may be this is a good time for me to start on emacs
- emacs was already installed on my machine, so I went through the in-built tutorial. Again, based on comments, this seemed to be the best way of learning emacs. After crossing around 35% of the tutorial, I felt fairly ok to *start* on using emacs. Mind you, at this stage, I knew to navigate, a bit of yank and kill, and some keys that I remembered. Nothing fancy
- Then I tried to ‘execute’ the lisp code. The first function was rather simple
(defun myfn() (+ 2 3)). When I tried to do this from the standard emacs, I couldn’t figure out how this could be done. The standard keys of
M-x run-lispdidn’t work straight out of the box since I was not using clisp and the lisp was not installed in the default location. Trying to modify the
~/.emacsfile by trying something like this – didn’t help either. The
inferior-lisp-programvariable didn’t help it – the ccl wouldn’t execute. Or I would see warnings of swank that I didn’t understand.
- At this stage, I was very frustrated and thought that SLIME might be the only option out. Checking this from SLIME documentation, made me think that SLIME might be the one I need to check.
- So, next thing, installing SLIME. This meant, installing SLIME and configuring it for CCL Clozure’s trac is the location for the instructions.
- First download the beta-version of QuickLisp. QuickLisp is the apt-get / Maven / pypi / CPAN of Lisp. So, next thing to do, first download the quicklisp.lisp file
curl -O http://beta.quicklisp.org/quicklisp.lisp
- Then load the quicklisp.lisp into CCL. Using
ccl64 -l quicklisp.lisp
- Then call the install method
- This will download the required files and a directory is created here
~/quicklispwith the required modules
(ql:quickload :quicklisp-slime-helper)on the same CCL session. This will install the SLIME modules for the CCL
- Then the ~/.emacs file has to be changed as mentioned in the http://trac.clozure.com/ccl/wiki/InstallingSlime. I provided the location of the ccl64 script file for the inferior-lisp-program variable.Also, instead of providing the location for the SLIME installation, provide the location of the slime-helper.el ;;(add-to-list ‘load-path “~/code/slime/”) ;or wherever you put it
(load (expand-file-name "~/quicklisp/slime-helper.el")) (setq inferior-lisp-program "~/code/tools/ccl/scripts/ccl64 -K utf-8" )More information on configuring SLIME is on SO
- Then the next step is to load SLIME. Before that, open the file that you want to compile.
C-x C-f ~/code/test1.lisp
- Then load SLIME.
M-x slime. If all is well, you should be prompted with a
CL-USER>REPL prompt. You can test that the CCL is working by doing some simple function calls
(defun myfn() (+ 2 3))and calling this function
(myfn), should do the trick.
- Then the next thing to do is to be able to ‘compile’ the existing files loaded in the editor. On the file buffer, you can compile the file by typing
C-c C-k. If the file doesn’t have any errors, you will see a message ‘compilation finished’
- The nice bit of this is that the SLIME gets the latest definitions if the file has been modified. So, you can switch to the SLIME buffer,
C-x b, will switch to the last used buffer and you can call the function name to see that the new changes are picked up or not.
- And btw, to exit the lisp REPl, the function to use is
Hopefully the above instructions help you setup emacs, Clozure CL, SLIME and get you started on writing some Lisp code. I am still learning emacs, and a tip here – start with the inbuilt tutorial. It is a bit long, but it will be worth the time. I will publish my cheat-code for the emacs keys in the future some time.