2
votes

I'm using Emacs as my Common Lisp (SBCL, to be exact) editor, with SLIME. I set up Quicklisp as per the instructions here, and checked if it worked outside of SLIME, and everything was fine - I could grab and download code, include it, everything.

Now, I was trying to use the Compile/Load File command in Emacs for a source file with the following at the top:

(ql:quickload "priority-queue")

(defpackage :tournament
  (:use :cl :priority-queue))

(in-package :tournament)

Now, once again, not in SLIME, this worked fine. However, in SLIME, I get an error of the following form:

The name "PRIORITY-QUEUE" does not designate any package.
  [Condition of type SB-KERNEL:SIMPLE-PACKAGE-ERROR]

Plus a backtrace, of course. Am I missing something in particular? I installed slime using package-install from Emacs, and I have the following code in my .emacs file to set it up:

(setq inferior-lisp-program "/usr/local/bin/sbcl")
(require 'slime)
(slime-setup)
1

1 Answers

4
votes

This is happening because of the separate times of compilation and loading.

When compiling, plain function calls (like ql:quickload) are not evaluated. When the compiler tries to process the defpackage form (which is not a plain function call, but a macro that has side-effects at compile-time), the function that loads "priority-queue" has not been called and the package is not available.

You won't see this if you load the file instead of compiling and loading, because load evaluates each form as it loads.

There are a few options available. The simplest is to wrap your call to ql:quickload in eval-when, e.g.

(eval-when (:compile-toplevel :load-toplevel :execute)
  (ql:quickload "priority-queue"))

I prefer to define a system for my projects, however small, so I would make a tournament.asd file that looks like this:

(asdf:defsystem #:tournament
  :depends-on (#:priority-queue)
  :serial t
  :components ((:file "tournament.lisp")))

I'd put that in ~/quicklisp/local-projects/tournament/ (along with tournament.lisp) and use (ql:quickload "tournament") in the repl to get started and load it.

I use that latter setup so often that I wrote a Lisp program to do it for me called quickproject.