Search code examples
common-lispsbcl

Can someone recommend some documentation on package management for SBCL/Common Lisp?


thanks in advance for the help.

Two-part question:

Part 1.

Can anyone recommend some documentation on package management for SBCL? I'm having a lot of trouble and getting surprising errors, and would love to know that I'm reading the right stuff.

Part 2.

I'd like to be able to solve my own problem, but I know that this group prefers to have reproducible issues so I'll outline what's going wrong below:

  1. I wish to build a package consisting of my code, along with the :cl :postmodern and :frugal-uuid packages.
  2. I use (cl-project:make-project #P"/home/oliver/quicklisp/local-projects/hsm to establish a system.
  3. I populate the following in main.lisp in the above project folder:
(ql:quickload :frugal-uuid)
(ql:quickload :postmodern)

(defpackage hsm
  (:use :cl :frugal-uuid :postmodern))
(in-package :hsm)

Below which I define my functions.

When I evaluate (ql:quickload :hsm), I get the following error:

Package FRUGAL-UUID does not exist.

Note that if I evaluate the above expressions from 3. in the REPL it works with no errors.


Solution

  • Directly calling quickload from source files is not great:

    (ql:quickload :frugal-uuid)
    (ql:quickload :postmodern)
    

    Here I suppose your hsm.lisp file is being compiled, and the corresponding calls to ql:quickload are emitted in the object file, so that when it is loaded, the code is going to be executed. But, when compiling the file, the compiler encounters defpackage which expands as an (eval-when (:compile-toplevel ...)...) which forces evaluation to happen during compilation. At this point, :frugal-uuid is not yet loaded because this is going to happen later, when the compiled file will be loaded.

    You could also put calls to ql:quickload inside eval-when blocks to force the dependencies to be loaded when compiling, but the best way is to organize your code into systems.

    Using cl-project:make-project, you should have an hsm.asdf file at the root of your project, containing something like this:

    (defsystem "hsm"                                                                                                                                                                                                                     
      :version "0.1.0"                                                                                                                                                                                                                            
      :author ""                                                                                                                                                                                                                                  
      :license ""                                                                                                                                                                                                                                 
      :depends-on ()                                                                                                                                                                                                                              
      :components ((:module "src"                                                                                                                                                                                                                 
                    :components                                                                                                                                                                                                                   
                    ((:file "main"))))                                                                                                                                                                                                            
      :description ""                                                                                                                                                                                                                             
      :in-order-to ((test-op (test-op "hsm/tests"))))   
    

    Here you can change the dependencies of your project:

    :depends-on (:frugal-uuid :postmodern)
    

    so that when you quickload :hsm, it also loads its dependencies.