It's 2019 and Lisp stories are on fire at HackerNews. While there exist multiple Lisp dialects, Common Lisp is the oldest and most mentioned. Thus, if you're looking to get started with programming in Common Lisp, then there are 2 options:
As for me, I did not feel like learning a brand new text editor just to get started with Lisp so I went with Roswell.
Follow the instructions on installing Roswell for your platform. In my case, I decided to install it under
$HOME/bin on my linux machine via:
$ sudo apt install rlwrap $ mkdir $HOME/bin $ git clone -b release https://github.com/roswell/roswell.git $ cd roswell/ $ sh bootstrap $ ./configure --prefix=$HOME/bin $ make $ make install
Make sure to add the roswell path to your
~/.bashrc (note that roswell installed itself under
~/bin/bin and if this looks odd to you, install it under
$HOME/apps or something of the
if [ -d "$HOME/bin/bin" ] ; then PATH="$HOME/bin/bin:$PATH" fi
Open a new terminal and setup roswell:
$ which ros /home/xxx/bin/bin/ros $ ros --version roswell 19.06.10.100 $ ros setup
We will now setup VSCode to run lisp. First install the vscode-lisp extension. Open a new file and type the following in:
(defun main () (format t "Hello world"))
Then launch a terminal inside VSCode. In
the terminal run
rlwrap ros run to start the REPL (Read/Eval/Print Loop). Select the above defined
function and use the "Run Selected Text in Active Terminal" from the Command Palette (F1) to run your code!
Note that you can exit the REPL via:
rlwrap utility remembers previously
typed commands which makes for a much nicer REPL experience.
What is amazing about Roswell is that is comes with a scripting / build ability that allows you to easily distribute
your application. To see this in action first create a roswell script via
ros init hello-world. Then add
in the following code so that your script looks like the following:
#!/bin/sh #|-*- mode:lisp -*-|# #| exec ros -Q -- $0 "$@" |# (progn ;;init forms (ros:ensure-asdf) ;;#+quicklisp(ql:quickload '() :silent t) ) (defpackage :ros.script.hello-world.3774807541 (:use :cl)) (in-package :ros.script.hello-world.3774807541) (defun helloWorld () (format t "Hello world") ) (defun main (&rest argv) (declare (ignorable argv)) (helloWorld)) ;;; vim: set ft=lisp lisp:
We can now simply run this script via
ros hello-world.ros but more interestingly, we can actually compile
a binary via
ros build hello-world.ros && ./hello-world.
Interestingly enough, I am not a complete noob to Common Lisp, I actually programmed it 15 years ago during my
undergrad years. A colleague and I
compared an experimental genetic algorithm against an ant colony optimization algoritm on a path-finding problem. Once I had lisp running I opened up the project and basically executed
ants.lisp in the REPL, ran
(INITIALIZE-ANT-WORLD) followed by
(DISPATCH-ANTS) and voila, my ants were able to find
No guide to getting started with Lisp would be complete without a list of further reading that will keep you busy for the next 100 years so here we go:
Well, that's about it - Lisp is beautiful and I'm off to wrap my head around some 15 year old code that doesn't look too bad, go functional programming!
Back to the article list.
Subscribe to get articles as they are published direct to your inbox!