4. Setting up the development environment

The first step will be to prepare our development environment. We will go straight for the crème de la crème of the Common Lisp ecosystem. We will install SBCL (Steel Bank Common Lisp) as our Common Lisp interpreter and Emacs as our IDE or code editor. I will assume you have basic programming knowledge and know how to use Emacs, at least in a basic way.

Before continuing, let's understand what each piece of the environment we are going to install is:

  • SBCL: A Common Lisp compiler and interpreter. It is responsible for running our code.
  • Emacs: A very powerful and extensible text editor, widely used in the Lisp communities. Technically speaking it is an Emacs Lisp interpreter itself, but that is not relevant to us right now.
  • SLIME: A development environment for Common Lisp that integrates with Emacs. It provides features such as autocompletion, debugging, and interactive code evaluation.
  • Quicklisp: A package manager for Common Lisp that makes installing and managing libraries easier.

Now we can get started.

If you are working on Linux, you need to install the sbcl, slime, and emacs packages. On Debian/Ubuntu you can do this by running the following command in the terminal:

sudo apt-get install sbcl slime emacs

If you are using macOS, you can install SBCL and Emacs using Homebrew. Run the following commands in the terminal:

brew install sbcl emacs

On Windows, however, you will need to download the installers from the official pages or consider using Portacle.

Now we will install Quicklisp, the most popular package manager in the Common Lisp ecosystem. Open a terminal and run the following commands:

curl -o /tmp/ql.lisp http://beta.quicklisp.org/quicklisp.lisp
sbcl --no-sysinit --no-userinit --load /tmp/ql.lisp \
       --eval '(quicklisp-quickstart:install :path "~/.quicklisp")' \
       --eval '(ql:add-to-init-file)' \
       --quit
sbcl --eval '(ql:quickload :quicklisp-slime-helper)' --quit

Then add the following lines to your Emacs configuration file, ~/.emacs.d/init.el, to load Quicklisp automatically when SLIME starts:

(load (expand-file-name "~/.quicklisp/slime-helper.el"))
(setq inferior-lisp-program "sbcl")

Open Emacs and run M-x slime to start SLIME. You should see a Common Lisp REPL (Read-Eval-Print Loop). Type:

(+ 2 3)

and press Enter. You should see the result 5.

We are ready!

When you work on an exercise, I recommend following this workflow:

  1. Create a new file with the name of the problem, for example p01.lisp.
  2. Run M-x slime in Emacs to open the SLIME REPL.
  3. When you want to evaluate your code, place the cursor in the function and press C-c C-c. This will compile and load the function into the REPL.
  4. To test the function, you can type the code directly in the REPL or create a function in the file, place the cursor at the end of the expression, and use the C-x C-e combination. It will show the result in the REPL.

And with that we are ready to learn the basics of the language.

Building SPAs with Django and HTML Over the Wire: Learn to build real-time single page applications with Python

Building SPAs with Django and HTML Over the Wire: Learn to build real-time single page applications with Python

The HTML over WebSockets approach simplifies single-page application (SPA) development and lets you bypass learning a JavaScript rendering framework such as React, Vue, or Angular, moving the logic to Python. This web application development book provides you with all the Django tools you need to simplify your developments with real-time results.

Buy the book

Help me keep writing

Every coffee gives me a push toward the next article.

Comments

There are no comments yet.