学习《Practical Common Lisp》:搭建可开发非小型程序的Common Lisp环境
Hey there! Since you're working through Practical Common Lisp and ready to move beyond just typing into the REPL for larger projects, let's break down the best tools and setup steps for you. You've already tried Lisp in a Box and Portacle—both solid out-of-the-box options, but let's look at more flexible setups that scale well as your codebase grows.
Emacs + SLIME (The Gold Standard for Common Lisp)
If you're willing to learn a bit of Emacs (it's absolutely worth it for Lisp development!), this combo is the industry standard. SLIME (Superior Lisp Interaction Mode for Emacs) gives you tight, seamless integration with your Lisp implementation—think real-time code evaluation, interactive debugging, smart auto-completion, and REPL sync that keeps your code and runtime in lockstep. It's perfect for building and maintaining non-trivial Lisp programs.
VS Code + Common Lisp Extension (For VS Code Enthusiasts)
If you prefer the familiarity of VS Code, there's a solid extension ecosystem for Common Lisp. The most popular pick is the "Common Lisp" extension by ahungry, which adds REPL integration, one-click code loading, syntax highlighting, and basic refactoring tools. It's a great choice if you don't want to learn Emacs but still need a proper editor for larger projects.
Setting Up Emacs + SLIME
1. Install a Lisp Implementation (SBCL Recommended)
First, you need a working Common Lisp runtime. Steel Bank Common Lisp (SBCL) is the most widely used and well-supported option:
- Ubuntu/Debian: Run
sudo apt install sbcl - macOS: Use Homebrew:
brew install sbcl - Windows: Download the official installer from the SBCL site and follow the prompts.
2. Install Emacs
- Ubuntu/Debian:
sudo apt install emacs - macOS:
brew install emacs(or use the pre-built app from the Emacs official site) - Windows: Download the official installer or use Chocolatey:
choco install emacs
3. Configure SLIME in Emacs
Open your Emacs config file (usually ~/.emacs.d/init.el or ~/.emacs). Add the following to set up SLIME with SBCL:
;; Enable package manager (require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) (package-initialize) ;; Install SLIME if not already present (unless (package-installed-p 'slime) (package-refresh-contents) (package-install 'slime)) ;; Link SLIME to SBCL (setq slime-lisp-implementations '((sbcl ("sbcl"))))
Save the file and restart Emacs.
4. Test Your Setup
- Open Emacs and run
M-x slime(press Alt+X, typeslime, hit Enter). This will launch the SBCL REPL inside Emacs. - Create a new file with
C-x C-f(Ctrl+X, Ctrl+F), name itmy-project.lisp, and write some code (e.g.,(defun greet (name) (format t "Hello, ~a!" name))). - Save the file with
C-x C-s. - Compile the entire file with
C-c C-k—this loads your code into the REPL. - Call your function in the REPL:
(greet "Lisp")—you should see the output! - To compile a single function, place your cursor inside the function definition and run
C-c C-c.
Setting Up VS Code + Common Lisp Extension
1. Install VS Code
Grab the latest version from the official site and install it.
2. Install SBCL
Follow the same steps as above to install SBCL on your system.
3. Install the Common Lisp Extension
Open VS Code, go to the Extensions tab (Ctrl+Shift+X), search for "Common Lisp" by ahungry, and install it.
4. Configure the Extension
- Open the extension settings (right-click the extension > Extension Settings).
- Under "Common Lisp: Lisp Path", enter the full path to your SBCL executable (e.g.,
/usr/bin/sbclon Linux,/usr/local/bin/sbclon macOS,C:\Program Files\sbcl\sbcl.exeon Windows).
5. Test Your Setup
- Create a new file named
my-project.lispand write some code. - Open the command palette (Ctrl+Shift+P) and run "Common Lisp: Start REPL"—this will open a REPL terminal in VS Code.
- Run "Common Lisp: Load File" to load your code into the REPL.
- Save changes with Ctrl+S, then reload the file to pick up updates.
Books
- Practical Common Lisp (you're already reading this!): The later chapters dive deeper into project organization with SLIME, so keep an eye out for those sections.
- Land of Lisp: A fun, approachable book that includes practical examples of building Lisp programs with Emacs/SLIME.
- ANSI Common Lisp: The definitive reference for the Common Lisp language—great for looking up syntax and standard functions when you hit a roadblock.
Tutorials & Guides
- SLIME Official Docs: Inside Emacs, run
M-x slime-helpto access the built-in documentation, which covers all key features like debugging, code navigation, and project management. - Emacs for Lisp Developers: Look for community tutorials focused on "Emacs for Common Lisp"—they'll teach you shortcuts and workflows tailored specifically to Lisp development.
- VS Code Common Lisp Guide: The extension's official documentation (accessible via the VS Code Extensions tab) has tips for customizing keybindings, troubleshooting, and optimizing your setup.
内容的提问来源于stack exchange,提问作者sanket alurkar

