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:
- Create a new file with the name of the problem, for example
p01.lisp. - Run
M-x slimein Emacs to open the SLIME REPL. - 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. - 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-ecombination. It will show the result in the REPL.
And with that we are ready to learn the basics of the language.
This work is under a Attribution-NonCommercial-NoDerivatives 4.0 International license.
Desafíos de programación atemporales y multiparadigmáticos
Te encuentras ante un librillo de actividades, divididas en 2 niveles de dificultad. Te enfrentarás a los casos más comunes que te puedes encontrar en pruebas técnicas o aprender conceptos elementales de programación.
Buy the bookWill you buy me a coffee?
This is how I keep writing without ads or paywalls.
Sure, it's on me!
Comments
There are no comments yet.