<h1id="title-non-xs"><ahref="index.html">The Common Lisp Cookbook</a>– Getting started</h1>
<!-- Announcement we can keep for 1 month or more. I remove it and re-add it from time to time. -->
<pclass="announce">
📹 <ahref="https://www.udemy.com/course/common-lisp-programming/?couponCode=6926D599AA-LISP4ALL">NEW! Learn Lisp in videos and support our contributors with this 40% discount.</a>
</p>
<pclass="announce-neutral">
📕 <ahref="index.html#download-in-epub">Get the EPUB and PDF</a>
</p>
<divid="content"
<p>We’ll begin with presenting easy steps to install a development environment and to start a new Common Lisp project.</p>
<p>Want a 2-clicks install? Then get
<ahref="https://shinmera.github.io/portacle/">Portacle</a>, <em>a portable and
multi-platform</em> Common Lisp environment. It ships Emacs, SBCL (the
implementation), Quicklisp (package manager), SLIME (IDE) and
Git. It’s the most straightforward way to get going!</p>
<h2id="install-an-implementation">Install an implementation</h2>
<h3id="with-your-package-manager">With your package manager</h3>
<p>If you don’t know which implementation of Common Lisp to use, try SBCL:</p>
<pre><code>apt-get install sbcl
</code></pre>
<p>Common Lisp has been standardized via an ANSI document, so it can be
implemented in different ways. See
<ahref="https://en.wikipedia.org/wiki/Common_Lisp#Implementations">Wikipedia’s list of implementations</a>.</p>
<p>The following implementations are packaged for Debian and most other popular Linux distributions:</p>
<ul>
<li><ahref="http://www.sbcl.org/">Steel Bank Common Lisp (SBCL)</a></li>
<li><ahref="https://gitlab.com/embeddable-common-lisp/ecl/">Embeddable Common Lisp (ECL)</a>, which compiles to C,</li>
<li><ahref="http://abcl.org/">ABCL</a>, to interface with the JVM,</li>
<li><ahref="https://ccl.clozure.com/">ClozureCL</a>, a good implementation with very fast build times (see this <ahref="http://mr.gy/blog/clozure-cl-deb.html">Debian package for Clozure CL</a>),</li>
<li><ahref="https://github.com/drmeister/clasp">CLASP</a>, that interoperates with C++ libraries using LLVM for compilation to native code,</li>
<li><ahref="https://gitlab.common-lisp.net/cmucl/cmucl">CMUCL</a>, originally developed at Carnegie Mellon University, from which SBCL is derived, and</li>
<li><ahref="https://en.wikipedia.org/wiki/GNU_Common_Lisp">GNU Common Lisp</a></li>
<li>and there is more!</li>
</ul>
<h3id="with-the-asdf-vm-package-manager">With the asdf-vm package manager</h3>
<p>The <ahref="http://asdf-vm.com/">asdf-vm</a> tool can be used to manage a large ecosystem of runtimes and tools.</p>
<ul>
<li><ahref="http://www.sbcl.org/">Steel Bank Common Lisp (SBCL)</a> is available via <ahref="https://github.com/smashedtoatoms/asdf-sbcl">this plugin</a> for <ahref="http://asdf-vm.com/">asdf-vm</a></li>
which is a library that helps on setting that up.</p>
<h3id="on-windows">On Windows</h3>
<p>All implementations above can be installed on Windows.</p>
<p><ahref="https://shinmera.github.io/portacle/">Portacle</a> is multiplatform and works on Windows.</p>
<p>You can also try:</p>
<ul>
<li><ahref="https://rho-emacs.sourceforge.io/">ρEmacs</a>, a preconfigured distribution of GNU Emacs specifically for Microsoft Windows. It ships with many CL implementations: CCL, SBCL, CLISP, ABCL and ECL, and also has components for other programming languages (Python, Racket, Java, C++…).</li>
<li><ahref="https://github.com/sharplispers/cormanlisp">Corman Lisp</a>, for Windows XP, Windows 2000, Windows ME or Windows NT. It is fully integrated with the Win32 API, and all the Windows API functions are readily available from Lisp.</li>
</ul>
<h2id="start-a-repl">Start a REPL</h2>
<p>Just launch the implementation executable on the command line to enter
the REPL (Read Eval Print Loop), i.e. the interactive
interpreter.</p>
<p>Quit with <code>(quit)</code> or <code>ctr-d</code> (on some implementations).</p>
<p>Here is a sample session:</p>
<pre><code>user@debian:~$ sbcl
This is SBCL 1.3.14.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* (+ 1 2)
3
* (quit)
user@debian:~$
</code></pre>
<p>You can slightly enhance the REPL (the arrow keys do not work,
it has no history,…) with <code>rlwrap</code>:</p>
<pre><code>apt-get install rlwrap
</code></pre>
<p>and:</p>
<pre><code>rlwrap sbcl
</code></pre>
<p>But we’ll setup our editor to offer a better experience instead of
working in this REPL. See <ahref="editor-support.html">editor-support</a>.</p>
<p>Lisp is interactive by nature, so in case of an error we enter the
debugger. This can be annoying in certain cases, so you might want to
use SBCL’s <code>--disable-debugger</code> option.</p>
<li>ASDF documentation: <ahref="https://common-lisp.net/project/asdf/asdf.html#Defining-systems-with-defsystem">defining a system with defsystem</a></li>
</ul>
<h3id="how-to-load-an-existing-project">How to load an existing project</h3>
<p>You have created a new project, or you have an existing one, and you
want to work with it on the REPL, but Quicklisp doesn’t know it. How
can you do ?</p>
<p>Well first, if you create it or clone it into
one of <code>~/common-lisp</code>, <code>~/.local/share/common-lisp/source/</code> or
<code>~/quicklisp/local-projects</code>, you’ll be able to <code>(ql:quickload …)</code> it with no
further ado.</p>
<p>Otherwise you’ll need to compile and load its system definition
(<code>.asd</code>) first. In SLIME with the <code>slime-asdf</code> contrib loaded, type <code>C-c C-k</code>
(<em>slime-compile-and-load-file</em>) in the <code>.asd</code>, then you can
<code>(ql:quickload …)</code> it.</p>
<p>Usually you want to “enter” the system in the REPL at this stage:</p>
<li><ahref="https://github.com/vindarel/cl-cookieproject">cl-cookieproject</a> - a project skeleton for a ready-to-use project with an entry point and unit tests. With a <code>src/</code> subdirectory, some more metadata, a 5AM test suite, a way to build a binary, an example CLI args parsing, Roswell integration.</li>
<li>Source code organization, libraries and packages: <ahref="https://lispmethods.com/libraries.html">https://lispmethods.com/libraries.html</a></li>