Note: This post is now 1.5 years old. It uses OS X 10.4, and so may be out of date :(
Common Lisp for Common Folk
Many people in the CS community might associate Lisp with a certain snobbishness or air of superiority.
This has nothing to do with the supposed “power” or “versatility” of the language, nor does it relate to “parse trees”, “macros”, and “code=data”. No, the actual reason that Lisp is placed so high above the rest of us is that you have to be a Lisp-hacker just to figure out how to install Lisp on your computer.
So: Here are the simple steps required to install and use Common Lisp, spelled out for those of us who aren’t already Lisp-fluent. There is a chance these steps will work for you, but no guarantees: I swear they make it tough on purpose.
Some notes before we begin: On Linux, I am using Ubuntu 10.10. These steps should work similarly on any other Linux, but the way you install programs and your file paths may differ a bit. On Mac, I am using Snow Leopard.
First, we need a compiler/interpreter for Common Lisp. We’ll be using SBCL. Why this particular implementation? Cause it’s free and it works. If you prefer to use another instead, download that instead and modify the steps appropriately.
Second, we’ll ensure we have emacs, and then install Slime to go with it.
Finally, we’ll edit the emacs configuration file so that it will work with Slime and SBCL.
Installing on Linux Ubuntu:
- Get SBCL. From the command line, run:
sudo apt-get install sbcl
For all OSes, you can also download SBCL from their website (just click on the appropriate green box).
- Now you have a working Lisp Interpreter! You could be done right now! From the command line, just run
sbcland you’ll be in a working Lisp environment. Try running
(format t "Hello World!")or run
- Get emacs and Slime. Run:
sudo apt-get install emacsFor all OSes, you can also download and install Slime from the website.
sudo apt-get install slime
On Linux, odds are good you already have emacs, but you probably want to make sure it’s the latest version just in case.
- Configure emacs to play nice with Slime. Open the file ~/.emacs (create it if it doesn’t exist) and add the following lines:
;; use SBCL and Slime with lisp (setq inferior-lisp-program "/usr/bin/sbcl") ; tell emacs where the lisp interpreter is (add-to-list 'load-path "/usr/share/emacs/site-lisp/slime") ; tell emacs where slime is (require 'slime) (slime-setup '(slime-fancy)) ; load almost all slime packages (minimalist: use (slime-setup))
You must make sure to change the paths in lines 2 and 3 to match your computer. For me, sbcl is located at “/usr/bin/sbcl” and the slime folder is at “/usr/share/emacs/site-list/slime”, so that’s what I put in the file. Yours are probably similar but you may have to search around a little to figure them out.
Installing on Mac OS X (Snow Leopard recommended)
- You’ll need to install MacPorts if you don’t have it. You can download Macports here.
- Install SBCL. Download SBCL from their website (just click on the appropriate green box).
- Install emacs: Luckily, there is a site just for you. Download and install. We also need to be able to use the “alt” or “option” key as the meta key. In Snow Leopard, you can do so this way: With Terminal Open, go to the Terminal menu and click Preferences. Under the Settings tab, find the Keyboard tab, and at the bottom is a check box: “Use option as meta key.” Check it.
- Install Slime. Download the file from their website and expand it to a folder. Mine was named “slime-2011-02-20”. Move this folder somewhere safe. I put mine in “/usr/share/emacs/site-lisp/” just like on Linux. Note /usr is an invisible folder in Macintosh HD.
- Configure the ~/.emacs file to work with Slime (create it if necessary; remember it’s an invisible file). Mine looked like this:
;; use SBCL and Slime with lisp (setq inferior-lisp-program "/opt/local/var/macports/software/sbcl/1.0.45_0/opt/local/bin/sbcl") ; tell emacs where the lisp interpreter is (add-to-list 'load-path "/usr/share/emacs/site-lisp/slime-2011-02-20") ; tell emacs where slime is (require 'slime) (slime-setup '(slime-fancy)) ; load almost all slime packages (minimalist: use (slime-setup))
The strings on lines 2 and 3 are where my “sbcl” program and my slime folder are located. You’ll need to change them to match where your files are located.
Nice work. To try Slime out, go to the command line and run
to open up emacs. If you type Alt-x slime (that is: hold alt while pressing x, then type slime, then press enter), you should be inside Slime. Try
(format t "C++ rules!"). Press Ctrl-x Ctrl-c to quit.
If these steps didn’t work for you, leave a comment and let me know! If they did work, leave a comment and send cash!
Link of the day: Chess + Music + 80s= Pure Awesomeness