Development environment setup for Lisp

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.

  1. 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
  2. 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)
  3. 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.
  4. The installation required unzipping the file and that was very simple. Another change I did was to the $CCLDIR/scripts/ccl and $CCLDIR/scripts/ccl64 files, providing the directory for the CCL_DEFAULT_DIRECTORY
  5. 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
  6. 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
  7. 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-lisp didn’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 ~/.emacs file by trying something like this –  didn’t help either. The inferior-lisp-program variable didn’t help it – the ccl wouldn’t execute. Or I would see warnings of swank that I didn’t understand.
  8. 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.
  9. So, next thing, installing SLIME. This meant, installing SLIME and configuring it for CCL Clozure’s trac  is the location for the instructions.
  10. 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
  11. Then load the quicklisp.lisp into CCL. Using ccl64 -l quicklisp.lisp
  12. Then call the install method (quicklisp-quickstart:install)
  13. This will download the required files and a directory is created here ~/quicklisp with the required modules
  14. Then (ql:quickload :quicklisp-slime-helper) on the same CCL session. This will install the SLIME modules for the CCL
  15. Then the ~/.emacs file has to be changed as mentioned in the 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
  16. 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
  17. 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.
  18.  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’
  19. 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.
  20. And btw, to exit the lisp REPl, the function to use is (quit)

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.