Skip to content
Tutorials Center
My learning

Topics

Lesson 34 of 38 ยท Libraries and Tooling

Quicklisp and the Common Lisp Library Ecosystem

Install Quicklisp, load libraries with ql:quickload, explore dists, Ultralisp and Roswell, and tour essential Common Lisp libraries for utilities, strings, regex, JSON, HTTP and threads.

Common Lisp's standard is large but old, so day-to-day programs lean on libraries for HTTP, JSON, regular expressions, date handling and more. Quicklisp is the library manager nearly everyone uses: it downloads, builds and loads libraries (and their dependencies) from a curated monthly snapshot.

Quicklisp and the libraries need a real Common Lisp implementation and network access, which this site does not provide. Lisp code and shell commands are read-only; JavaScript examples are labelled stand-ins that model utility functions and version resolution.

Installing Quicklisp

Install an implementation first (SBCL is the most common). Then:

Terminal
curl -O https://beta.quicklisp.org/quicklisp.lisp
sbcl --load quicklisp.lisp

At the REPL:

LISP
(quicklisp-quickstart:install)
(ql:add-to-init-file)     ; loads Quicklisp automatically when the REPL starts

quicklisp-quickstart:install creates ~/quicklisp/. ql:add-to-init-file edits your implementation's init file (~/.sbclrc for SBCL). Check the download's signature as the Quicklisp site describes if you need to verify it.

Loading and finding libraries

LISP
(ql:quickload "alexandria")           ; download if needed, compile, load
(ql:quickload '("cl-ppcre" "local-time"))
(ql:system-apropos "json")            ; search the dist for matching systems
(ql:update-dist "quicklisp")          ; newer monthly snapshot
(ql:update-client)

ql:quickload loads systems through ASDF (see the systems lesson), so anything it can load is an ordinary ASDF system. In your own .asd, list libraries under :depends-on and load your system with (ql:quickload "myapp"), which fetches the missing dependencies for you.

Quicklisp's ~/quicklisp/local-projects/ directory is scanned for your own systems, which is the easiest way to develop several projects together.

Other sources

Tool What it adds
Ultralisp a Quicklisp dist updated every few minutes from GitHub projects; add it with (ql-dist:install-dist "http://dist.ultralisp.org/" :prompt nil)
Roswell an installer and script runner for implementations and libraries (ros install sbcl, ros run)
Qlot per-project dependency pinning, like a lockfile
OCICL an OCI-registry-based system manager with lockfiles
CLPM another version-aware manager

Pinning matters in production: a monthly dist snapshot makes builds reproducible, and Qlot or OCICL record exact versions per project.

A tour of essential libraries

The following table names well-established libraries, grouped by purpose. I describe what each does; check each project's README for the current API before using it.

Need Libraries
general utilities Alexandria (curry, compose, with-gensyms, flatten, hash-table-keys, when-let), Serapeum (many extras), UIOP (portable OS/file/process utilities shipped with ASDF)
strings str, cl-ppcre (Perl-compatible regular expressions), split-sequence
iteration the built-in loop, plus iterate (a Lispier alternative)
dates and times local-time, cl-date-time-parser
JSON Jonathan, Yason, cl-json, Shasht
HTTP clients Dexador, Drakma
web servers Hunchentoot, Clack plus Ningle or Caveman, Woo
HTML generation cl-who, Spinneret
databases cl-dbi, Postmodern (PostgreSQL), Mito (ORM)
concurrency Bordeaux-Threads, lparallel, Chanl/cl-async
networking usocket
CLOS/MOP closer-mop, trivial-garbage, trivial-features
testing FiveAM, Parachute, Rove
command lines Clingon, unix-opts

A taste of the API:

LISP
(ql:quickload '("alexandria" "cl-ppcre" "str"))

(alexandria:flatten '(1 (2 (3 4)) 5))            ; => (1 2 3 4 5)
(funcall (alexandria:curry #'+ 10) 5)            ; => 15
(funcall (alexandria:compose #'1+ #'abs) -5)     ; => 6
(cl-ppcre:scan-to-strings "(\\d+)-(\\d+)" "tel 555-1234")
;; => "555-1234", #("555" "1234")
(str:join "," '("a" "b" "c"))                    ; => "a,b,c"

Note that cl-ppcre strings need doubled backslashes because Lisp strings treat \ as an escape. Libraries are ordinary Lisp code, so reading their source is both easy and instructive.

JS Stand-in: Alexandria-style helpers

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Choosing a library

  1. Is it maintained? Look at the date of the last commit and whether the code is in a recent Quicklisp dist.
  2. Portability. Does it support your implementations (SBCL, CCL, ECL, ABCL, Allegro, LispWorks)? Does it use bordeaux-threads or uiop rather than implementation internals?
  3. Dependencies. A small library that pulls in forty others is a cost.
  4. License. Most Lisp libraries use MIT, BSD or LLGPL; check yours.
  5. Tests and docs. A test system and a README with examples usually signal care.

Using a library in your own system

Declare it, import selectively and keep your package clean:

LISP
(defpackage :myapp.text
  (:use :cl)
  (:import-from :alexandria #:when-let #:with-gensyms)
  (:local-nicknames (#:re #:cl-ppcre)))

(in-package :myapp.text)

(defun phone-parts (s)
  (re:register-groups-bind (area number) ("(\\d{3})-(\\d{4})" s)
    (list area number)))

Dependency resolution, conceptually

Quicklisp resolves a system's :depends-on recursively from the dist index, downloads archives, and asks ASDF to compile and load them in dependency order. A dist is a consistent set: every library version in a monthly dist was built successfully against the others at that time. That is why updating the dist can fix or introduce breakage together rather than one library at a time.

JS Stand-in: resolving a dependency tree

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does (ql:quickload "cl-ppcre") do?

    quickload fetches missing systems from the dist and loads them through ASDF.
  2. 2. Why does a Quicklisp dist give reproducible builds?

    Monthly dists are tested as a set, so pinning a dist pins a known-good combination.
  3. 3. Which tool is commonly used to pin per-project library versions?

    Qlot and OCICL provide lockfile-style pinning on top of dists and registries.
  4. 4. Why do cl-ppcre patterns in Lisp strings need doubled backslashes?

    The string reader consumes one level of escaping before the regex engine sees the text.

Summary

  • Quicklisp installs and loads libraries with ql:quickload; dists are curated, consistent snapshots.
  • Ultralisp, Roswell, Qlot and OCICL cover fresher libraries, scripting and version pinning.
  • Alexandria, cl-ppcre, local-time, Dexador, Hunchentoot, Bordeaux-Threads and FiveAM are the staples.
  • Import selectively and use local nicknames; evaluate libraries on maintenance, portability and dependencies.
  • The JavaScript snippets only illustrate what some helpers do and how resolution orders systems.

Next: Testing, Debugging and Delivering Lisp Programs