LISP - Environment
Lisp - Modern Development Environment Setup
Section titled “Lisp - Modern Development Environment Setup”Setting up a modern Common Lisp environment is easier than ever. The key to Lisp development is its interactive nature, centered around the REPL (Read-Eval-Print Loop). This guide focuses on current best practices for a powerful and productive setup.
1. Choose a Lisp Implementation
Section titled “1. Choose a Lisp Implementation”An implementation is the Lisp compiler and runtime. The most popular choice today is:
- Steel Bank Common Lisp (SBCL): A high-performance, open-source compiler that is the de-facto standard for new projects. It provides strong type checking and generates fast native code.
- Clozure Common Lisp (CCL): Another excellent, fast implementation known for its quick compile times and good support on macOS, Linux, and Windows.
- Embeddable Common Lisp (ECL): Useful for embedding Lisp in C/C++ applications or for building standalone executables.
We recommend starting with SBCL.
2. Install Lisp and Tools
Section titled “2. Install Lisp and Tools”The easiest way to install and manage Lisp implementations is with a version manager or your system’s package manager.
Recommended Method: Roswell
Section titled “Recommended Method: Roswell”Roswell is a Lisp installation/management utility, like nvm for Node.js or pyenv for Python. It simplifies installing implementations, managing scripts, and getting started. Check the official Roswell GitHub page for installation instructions.
# After installing Roswell, install SBCLros install sbcl-bin
# Set it as the defaultros use sbcl-binAlternative: System Package Manager
Section titled “Alternative: System Package Manager”# macOS (using Homebrew)brew install sbcl
# Debian/Ubuntusudo apt-get install sbcl
# Arch Linuxsudo pacman -S sbcl3. Set Up Your Editor for Interactive Development
Section titled “3. Set Up Your Editor for Interactive Development”Writing Lisp code in a plain text editor is possible, but the real power comes from an editor that integrates with a running Lisp process.
- Emacs + SLIME or SLY: This is the traditional gold standard. SLIME (Superior Lisp Interaction Mode for Emacs) and its successor SLY provide deep integration, allowing you to compile functions, inspect objects, and debug code, all from your editor, connected to a live Lisp REPL.
- Visual Studio Code + Alive: A fantastic modern alternative. The Alive extension provides a rich, SLIME-like interactive experience within the popular VS Code editor, making it very accessible for newcomers.
4. Your First Interactive Session
Section titled “4. Your First Interactive Session”Let’s start a REPL and run some code. Open your terminal and type sbcl.
$ sbclThis is SBCL ...* ; The asterisk is the REPL promptNow, you can type Lisp expressions, and the REPL will evaluate them and print the result.
* (+ 2 2)4
* (format t "Hello, Lisp World!~%")Hello, Lisp World!NILCreate a file named hello.lisp:
;;; hello.lisp
(defun hello () (format t "Hello from a file!~%"))
(format t "File loaded.~%")Now, load this file into your running REPL:
* (load "hello.lisp")File loaded.T
* (hello)Hello from a file!NIL
* ; To quit the REPL, type (quit) or press Ctrl+D* (quit)5. Project and Library Management
Section titled “5. Project and Library Management”Quicklisp is the essential library manager for Common Lisp. It lets you download, install, and manage thousands of open-source libraries with a single command. Follow the installation instructions on the official Quicklisp website. Once installed, you can load a library like this:
* (ql:quickload :drakma) ; Loads the Drakma HTTP client library