Note: this tutorial only outlines how to install and setup whats necessary to compile and run lisp on
Mac OS X
, it will not go over how to setup emacs or slime. Instead there will be instructions for how to get syntax highlighting on VsCode. If you don't have VsCode download and install it from here https://code.visualstudio.com/download
This tutorial is under the impression that you do not have Homebrew installed, if you do just skip the step.
Homebrew is a common installation tool on mac that will make the rest of this tutorial possible.
I dont know how?
If you don't know where that is hit Command + Space
on your keyboard to open up spotlight search.
A search bar should pop up. Once it does search for "terminal"
Click the first app. (Terminal.app
)
Note: it may ask u for permission or your password many times throughout this process, simply enter your Mac's password and continue by hitting Enter. It may also ask you yes/no questions
(y/n)
always typey
and hit enter.
Once your in the terminal copy the following and paste it, then hit enter to run:
xcode-select --install
Next copy and run the following:
curl -fsSL -o install.sh https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh
This will download Homebrew's necessary files. Once it finishes copy and run:
/bin/bash install.sh
This next step assumes you are using ZSH as it is the default for new Macs. Copy and run:
Im not sure what im using
If you are not sure what you are using, copy and run this:echo $0
You will see either bash
or zsh
which will be what you are using.
open ~/.zshrc
It didn't work / I'm using the Bash shell
If you are using the bash shell copy and run this instead:
open ~/.bash_profile
A text file should open up that may contain a lot of text. Simply go to the top of the file and hit enter a few times to make space, then copy and paste this into there:
# Add Homebrew's executable directory to the front of the PATH
export PATH=/usr/local/bin:$PATH
The first line is a comment that will help you remember what this does if you open this file in the future.
Once your done save the file then close it.
If you are using zsh
copy and run this:
source ~/.zshrc
If you are using bash
copy and run this:
source ~/.bash_profile
Now you should be done with the setup of Homebrew.
To verify that it is installed correctly copy and run:
brew doctor
If there are no updates you will see this:
Your system is ready to brew.
Note: you might get a warning to run
brew update
, if you do, run the command and follow the on screen instructions.
We will be using the Steel Bank Common Lisp (SBCL)
compiler. The compiler is what will compile your lisp
code and allow it to run
First open up the terminal or use the previous one you have opened.
Copy and run:
brew install sbcl
this is the lisp compiler
After it finishes copy and run:
brew install rlwrap
this is a readline wrapper which will be needed
Now you need to install lisp's package manager, quicklisp. Copy and run:
curl -o /tmp/ql.lisp http://beta.quicklisp.org/quicklisp.lisp
Next copy and run:
sbcl --no-sysinit --no-userinit --load /tmp/ql.lisp \
--eval '(quicklisp-quickstart:install :path "~/.quicklisp")' \
--eval '(ql:add-to-init-file)' \
--quit
Note: it may prompt you to hit enter, make sure you do.
To setup rutils
a lisp library we will be using, you need to do the following.
Copy and run:
open ~/.sbclrc
The file should contain some stuff, at the bottom of everything add these two lines:
(ql:quickload :rutils)
(cl:in-package :rtl-user)
If your concerned, in the end the file should look like this:
;;; The following lines added by ql:add-to-init-file:
#-quicklisp
(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp"
(user-homedir-pathname))))
(when (probe-file quicklisp-init)
(load quicklisp-init)))
(ql:quickload :rutils)
(cl:in-package :rtl-user)
Thats it, now everything for lisp should be setup.
In the extensions menu search for Common Lisp
Once you find it hit install. The extension provides syntax highlighting and autofill for your lisp code.
Open up any folder in VsCode and create a file called hello-world.lisp
Inside paste:
(defun hello ()
(format t "Hello World!"))
Save the file.
Next open up the terminal inside VsCode by hitting Command + </b> (the backtick is located to the left of the
1!` key)
Inside the terminal run
rlwrap sbcl
Next load the file using:
(load "hello-world.lisp")
Then run:
(hello)
this calls the hello()
method in your lisp code.
If done successfully you should see something like this:
➜ lispstuff rlwrap sbcl
This is SBCL 2.1.8, 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.
* (load "helloworld.lisp")
T
* (hello)
Hello World!
NIL
*
When your done, hit the trash button (kill terminal) on right side of the terminal or enter (exit)
.
Note: if you keep getting weird errors and cannot exit, you can type abort until the prefix is a
*
then u can exit again.
If you want to quickyly be able to run your lisp files as scripts:
rlwrap sbcl --script filename.lisp
Note: running lisp files like this will not let you load in external libraries such as
rutils
( a library we will be using in this course).
You can manually make lisp load your libraries when running the file as a script by adding:
(load "~/.sbclrc")
to the top of your main lisp file.