Common Lisp How-Tos
Next: From Elegance to Speed
Prev: A Daily Journal in Org Mode
Intro
I've been writing this post as I go, and you may still see changes if you check back from time to time.
This post is for writing about things I'm figuring out, and for keeping notes on what I want to figure out next, as I get ramped up on Common Lisp. When I'm done there will hopefully be stuff here other people can use.
There's a lot to love and admire about Common Lisp, but the language has some pointy bits that can at times make Clojure look friendly. With so many things to sort out I'm going to try to keep a few notes going forward just to keep it all organized. Caveat emptor, YMMV, USE AT YOUR OWN RISK, etc., etc.
Lessons Learned So Far
How Do I Set Up Common Lisp on a Mac?
I made a repo to automate how I set up a fresh SBCL install on a Mac, including Quicklisp. This gets me from zero to a working Emacs REPL system fairly quickly.
Note that I also set a LISP_HOME
environment variable in my
.bash_profile
which I use in the examples which follow.
How Do I Get Environment Variables from Lisp?
From the Common Lisp Cookbook:
(uiop:getenv "HOME")
How Do I Quickly Create a New Project?
(There is a nice writeup on how Lisp projects are organized.)
First, it seems it's best to pick a standard place to put your Lisp projects. I have a deep directory tree on my filesystem so would prefer to set that path as an environment variable; this makes the setup easy to port to another computer.
I made this bash
script, lisplib
:
#!/bin/bash
projname=${1?}
sbcl --non-interactive \
--disable-debugger \
--eval '(ql:quickload "cl-project")' \
--eval '(ql:quickload "cl-utilities")' \
--eval '(let* ((projname "'$projname'")
(home (sb-unix::posix-getenv "LISP_HOME"))
(projpath (concatenate '"'"'string home "/" projname)))
(cl-project:make-project (pathname projpath)))'
open -a /Applications/Emacs.app $LISP_HOME/$projname/src/main.lisp
(Omit the newlines inside the last single-quoted expression.)
When I, say, lisplib foo
, it creates the project using make-project
and opens the editor on the main source file.
How Do I Add Dependencies to One Of My Projects?
Add it to the .asd
file in the :depends-on
list.
How Do I Get My Local Projects Loadable By Other Projects?
I did this once:
$ cd ~/quicklisp
$ mv local-projects /tmp # Mine was basically empty...
$ ln -s $LISP_HOME local-projects
How Do I Get Dependencies Loaded
- put your project in the directory symlinked above;
- jack into your REPL;
- update
depends-on
in the project's.asd
file as you add dependencies; (ql:quickload <current-package>)
to pick up its dependencies.- Optionally, to get the correct namespacing for the package you're
working on, use
slime-repl-set-package
(C-c M-p
) to set the default package to the one you're working on (not 100% sure what effect this has yet)
How Do I Build Binaries?
How Do I Use Curses
(or equivalent)?
After some research I decided to follow in Steve Losh's footsteps and
use cl-charms
(tutorial here). This cost me multiple days due to some outdated
Homebrew packages, but worked out in the end after updating those and
reinstalling my Lisp setup.
How Do I Get Help?
Aside from Stack Overflow, the #lisp
channel on IRC was helpful to
me for the above issue.