<astyle="font-size: 120%"href="https://www.udemy.com/course/common-lisp-programming/?couponCode=LISPY-XMAS2023"title="This course is under a paywall on the Udemy platform. Several videos are freely available so you can judge before diving in. vindarel is (I am) the main contributor to this Cookbook."> Discover our contributor's Lisp course with this Christmas coupon.</a>
📕 <ahref="index.html#download-in-epub">Get the EPUB and PDF</a>
</p>
<divid="content"
<p>A <strong>system</strong> is a collection of Lisp files that together constitute an application or a library, and that should therefore be managed as a whole. A <strong>system definition</strong> describes which source files make up the system, what the dependencies among them are, and the order they should be compiled and loaded in.</p>
<h2id="asdf">ASDF</h2>
<p><ahref="https://gitlab.common-lisp.net/asdf/asdf">ASDF</a> is the standard build
system for Common Lisp. It is shipped in most Common Lisp
<em>“the Utilities for Implementation- and OS- Portability”</em>. You can read
<ahref="https://common-lisp.net/project/asdf/asdf.html">its manual</a> and the
<ahref="https://gitlab.common-lisp.net/asdf/asdf/blob/master/doc/best_practices.md">tutorial and best practices</a>.</p>
<p><aname="example"></a></p>
<h2id="simple-examples">Simple examples</h2>
<h3id="loading-a-system-definition">Loading a system definition</h3>
<p>When you start your Lisp, it knows about its internal modules and, by
default, it has no way to know that your shiny new project is located
under your <code>~/code/foo/bar/new-ideas/</code> directory. So, in order to load
your project in your image, you have one of three ways:</p>
<ul>
<li>use ASDF or Quicklisp defaults</li>
<li>configure where ASDF or Quicklisp look for project definitions</li>
<li>load your project definition explicitely.</li>
</ul>
<p>Please read our section on the <ahref="getting-started.html#how-to-load-an-existing-project">getting started#how-to-load-an-existing-project</a> page.</p>
<h3id="loading-a-system">Loading a system</h3>
<p>Once your Lisp knows what your system is and where it lives, you can load it.</p>
<p>The most trivial use of ASDF is by calling <code>asdf:load-system</code> to load your library.
Then you can use it.
For instance, if it exports a function <code>some-fun</code> in its package <code>foobar</code>,
then you will be able to call it with <code>(foobar:some-fun ...)</code> or with:</p>
<p>Also, you can use SLIME to load a system, using the <code>M-x slime-load-system</code> Emacs command or the <code>, load-system</code> comma command in the prompt.
The interesting thing about this way of doing it is that SLIME collects all the system warnings and errors in the process,
and puts them in the <code>*slime-compilation*</code> buffer, from which you can interactively inspect them after the loading finishes.</p>
<h3id="testing-a-system">Testing a system</h3>
<p>To run the tests for a system, you may use:</p>
<h4id="using-the-system-you-defined">Using the system you defined</h4>
<p>Assuming your system is installed under <code>~/common-lisp/</code>,
<code>~/quicklisp/local-projects/</code> or some other filesystem hierarchy
already configured for ASDF, you can load it with: <code>(asdf:load-system "foobar")</code>.</p>
<p>If your Lisp was already started when you created that file,
you may have to, either:</p>
<ul>
<li>load the new .asd file: <code>(asdf:load-asd "path/to/foobar.asd")</code>, or with <code>C-c C-k</code> in Slime to compile and load the whole file.
<ul>
<li>note: avoid using the built-in <code>load</code> for ASDF files, it may work but <code>asdf:load-asd</code> is preferred.</li>
</ul>
</li>
<li><code>(asdf:clear-configuration)</code> to re-process the configuration.</li>
</ul>
<h3id="how-to-write-a-trivial-testing-definition">How to write a trivial testing definition</h3>
<p>Even the most trivial of systems needs some tests,
if only because it will have to be modified eventually,
and you want to make sure those modifications don’t break client code.
Tests are also a good way to document expected behavior.</p>
<p>The simplest way to write tests is to have a file <code>foobar-tests.lisp</code>
and modify the above <code>foobar.asd</code> as follows:</p>