3

I am writing a (SBCL) Common Lisp program that has the following line at the top of the file:

(defpackage :my-package
  (:use :cl :cl-who :hunchentoot :parenscript))

I am running Emacs 25, SBCL and SLIME on MacOS.

Whenever I evaluate the line above, I always get this error at first:

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

Then, I run (ql:quickload "cl-who") and watch the CL-WHO package install. I repeat for the other two packages. Once I have done that, the form can be evaluated successfully.

The problem is that I need to do this each time I restart the Emacs (or Lisp process, which I assume is roughly equivalent in this case). Why is it that when I install something with Quicklisp it is not "remembered" for the next session? Am I doing something wrong?

Is this a problem with configurations or a general misunderstanding of how it is supposed to work?

coredump
  • 37,664
  • 5
  • 43
  • 77
MadPhysicist
  • 5,401
  • 11
  • 42
  • 107
  • 2
    Quicklisp deals with systems (defined with `ASDF:DEFSYSTEM`), not with packages (defined by `CL:DEFPACKAGE`). A system may define zero or more packages, which will only be available after the system is loaded (either using ASDF directly, or with `QL:QUICKLOAD`; the latter also downloads the system if it's not already available). Systems you have previously installed don't get loaded automatically, since you wouldn't want all your images to be cluttered with hundreds of libraries you don't actually use. To easily load your project and its dependencies, define an ASDF system for it. – jkiiski Jan 08 '18 at 06:56
  • 2
    Might help: [cookbook/getting-started#creating a new project](https://lispcookbook.github.io/cl-cookbook/getting-started.html#working-with-projects). Once you have an .asd and a `(asdf:defsystem`, C-c C-k it and now you can `ql:quickload` it. Dependencies are in the .asd, `:depends-on` list. Quicklisp installs libraries in `~/quicklisp/dists/quicklisp/software/`. – Ehvince Jan 08 '18 at 10:02

1 Answers1

9

Then, I run (ql:quickload "cl-who") and watch the CL-WHO package install. I repeat for the other two packages. Once I have done that, the form can be evaluated successfully.

You can quickload more than one system at once:

(ql:quickload '(:cl-who :hunchentoot :parenscript))

[...] each time I restart the Emacs (or Lisp process, which I assume is roughly equivalent in this case).

That's the case here, but notice that you can start a Lisp process from the shell and connect to it from Emacs. In that case, you could exit and restart Emacs without killing the Lisp process. Start a new REPL from the shell and create a server:

(ql:quickload :swank)
(swank:create-server :port 5000)

And then, call slime-connect from Emacs (with localhost and 5000 for the host and port parameters). That can be used also to monitor a running application.

Why is it that when I install something with Quicklisp it is not "remembered" for the next session?

The system is fetched, compiled and installed on your machine, which explains why the second time you quickload a project, it is faster. But a system is only loaded in your environment when you request it, either with Quicklisp or ASDF.

Define a system

See §6. Defining systems with defsystem for an introduction on how to define a system. Suppose you name your system stackoverflow. The simplest way to get started is to create the following file:

~/quicklisp/local-projects/stackoverflow/stackoverflow.asd

which contains:

(defsystem "stackoverflow"
  :depends-on ("cl-who" "hunchentoot" "parenscript"))

When you execute (ql:quickload "stackoverflow"), Quicklisp will load all its dependencies.

Instead of loading all the required systems, you only need to load a single one.

Either automatically load this system...

Lisp implementations can execute code at startup. One possible way for this is to execute the code from a configuration file: [.]ccl-init.lisp, .eclrc, .lispworks, .sbclrc (your case), etc. Execute quickload only if Quicklisp itself is available:

#+quicklisp
(ql:quickload "stackoverflow")   

... or dump an image with all systems preloaded

You can also load all the required systems, and dump an executable image. Start a fresh SBCL from a terminal (not from Slime), call (ql:quickload "stackoverflow"), and then:

(sb-ext:save-lisp-and-die "my-env" 
                          :executable t
                          :compression 9)

(compression is optional)

Then, an executable file named "my-env" should be created in the same directory. Each time you start it, you have a fresh Lisp environment containing the systems you loaded before saving the image.

coredump
  • 37,664
  • 5
  • 43
  • 77