iBoyko - "sort of" a website

Installing ASDF and Creating Systems in Common Lisp

This is a basic instruction on how to install and configure ASDF for Common Lisp and create a system

Posted by Yakov Boyko on January 20, 2018

When one's development skills advance, inevitably, he comes to a point where it becomes useful and even necessary to load and compile files in a certain order. The MAKE utility exists in the C-family of languages precisely for this reason. Common Lisp community also provides one with an analog of MAKE. It is called ASDF, which is short for "Another System Definition Facility".

As you can probably gather from its name, the ASDF utility helps one define a system, which is essentially a container for announcing project's dependencies, as well as potentially complex declarations about the compilation order.

A basic ASDF declaration may look something like this:


(defsystem lack-restful
  :version "0.1"
  :author ""
  :license ""
  :depends-on ()
  :components ((:module "src"
                :components
                ((:file "lack-restful"))))
  :description ""
  :long-description
  #.(with-open-file (stream (merge-pathnames
                             #p"README.markdown"
                             (or *load-pathname* *compile-file-pathname*))
                            :if-does-not-exist nil
                            :direction :input)
      (when stream
        (let ((seq (make-array (file-length stream)
                               :element-type 'character
                               :fill-pointer t)))
          (setf (fill-pointer seq) (read-sequence seq stream))
          seq)))
  :in-order-to ((test-op (test-op lack-restful-test))))

For someone working on relatively simple Common Lisp projects, the most interesting field in the above sample is probably the :depends-on () field. It allows one to specify packages in which the current system depends.

Let's illustrate the key points of installing ASDF as well as its basic use.

It is most rewarding to use the ASDF in conjunction with the Quicklisp package manager because one can easily require packages within ASDF declarations, while the Quicklisp will automatically fetch them from its directory.

Hence, as the first step, make sure you install Quicklisp and get it working well with your Common Lisp implementation. The Common Lisp I am using is SBCL.

Next, run something like (ql:quickload "cl-project")

in your Lisp's REPL (either SBCL in Terminal or SLIME in Emacs). This will install a package called Cl-PROJECT, which is a basic boilerplate code generator for a Common Lisp project.

To see it in action, run something like this in your Lisp's REPL:

(cl-project:make-project #P "/home/my-user/projects/lack-restful") As a result, the CL-PROJECT will create the following structure within the specified directory: