Common Lisp Friday

Introduction

by Peter Hillerström / @peterhil

Lisp History

Lisp was invented by John McCarthy in 1958 while he was at the Massachusetts Institute of Technology (MIT).

McCarthy published it’s design in a paper entitled “Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I” (HTML|PDF) in 1960, in which he showed that with a few simple operators and a notation for functions, one can build a Turing-complete language for algorithms.

Family of languages

Lisp (historically, LISP) is a family of computer programming languages with a long history and a distinctive, fully parenthesized Polish prefix notation.

Originally specified in 1958, Lisp is the second-oldest high-level programming language in widespread use today.

Lisp has changed a great deal since its early days, and a number of dialects have existed over its history.

Lisp Dialects

Today, the most widely known general-purpose Lisp dialects are Common Lisp and Scheme.

Timeline of Lisp dialects
1955 1960 1965 1970 1975 1980 1985 1986 1990 1995 2000 2005 2012
Lisp 1.5 Lisp 1.5
Maclisp Maclisp
ZetaLisp ZetaLisp
NIL NIL
Interlisp Interlisp
Common Lisp Common Lisp
Scheme Scheme
ISLISP ISLISP

The parenthesis

(S-expressions)

Xkcd – Lisp cycles

The syntax

(function parameter second-parameter third-parameter)
CL-USER> (+ 3 7 5)
15
CL-USER> (first (list "a" "b"))
"a"

Quoting to prevent evaluation (equivalent ways):

(quote (a b c))
'(a b c)

Take this REPL,
my brother and may
it serve you well!

Instructions for the hackathon

There are many implementations of the ANSI Common Lisp standard, two implementations that you can use in the hackathon are SBCL and Clozure Common Lisp.

If you feel confident using basic Emacs editing command, I recommend using SBCL with Emacs and SLIME. Otherwise I recommend installing Clozure CL.

Also install Quicklisp if using either Common Lisp implementation.

Steps for installing SBCL with SLIME and Emacs

SBCL is acronym for Steel Bank Common Lisp.
SLIME is acronym for Superior Lisp Interaction Mode for Emacs.

1) Install SBCL

➜ sudo port install sbcl

2a) Install SLIME and Emacs using Macports

There are two alternative methods of installing SLIME.

Install SLIME with MacPorts or apt-get
(will also install emacs and Emacs.app)

➜ sudo port install slime

Copy dot.emacs into ~/.emacs to have the settings for SLIME as described by the port install

2b) Install SLIME and Emacs using Quicklisp

There are two alternative methods of installing SLIME.

Install Quicklisp (see instructions)

Type within Lisp REPL:

* (ql:quickload "quicklisp-slime-helper")

Add this to your ~/.emacs:

(load (expand-file-name "~/quicklisp/slime-helper.el"))
;; Replace "sbcl" with the path to your implementation
(setq inferior-lisp-program "sbcl")

3) Optionally install Aquamacs

4) Start SLIME with SBCL

open -a /Applications/MacPorts/Emacs.app
OR
open -a /Applications/Aquamacs.app

Type in Emacs or Aquamacs:

meta-x slime
(meta key is usually mapped to option, tapping ESC before the key also works)

Steps for installing Clozure Common Lisp (CCL)

Takes ~30 min. with hassling around and
asking questions and/or googling.

1) Check out Clozure Common Lisp from the Subversion [~2-3 min]

svn co http://svn.clozure.com/publicsvn/openmcl/release/1.8/darwinx86/ccl

2) Build it

[~5 min]
➜ cd ccl
➜ ./dx86cl64 --no-init
Welcome to Clozure Common Lisp Version 1.8-r15286M  (DarwinX8664)!
? (rebuild-ccl :full t)
; lots of output
? (quit)

3) Install the command line start script and set the ccl directory env variable

[~1 min]
➜ sudo cp scripts/ccl64 /usr/local/bin
➜ export CCL_DEFAULT_DIRECTORY="`pwd`"  # put this into .zshrc or .bashrc
➜ echo $CCL_DEFAULT_DIRECTORY         
/Users/peterhil/Programming/Lisp/ccl
➜ rehash  # if using zsh

4) Build the Cocoa IDE

[~ 1 min]
ccl64
Welcome to Clozure Common Lisp Version 1.8-r15485M  (DarwinX8664)!
? (require :cocoa-application)
; lots of outputopen Clozure\ CL64.app/

5) Optional – start CCL inside Emacs or Aquamacs using SLIME:

Install SLIME as described in SBCL instructions above.

In Emacs or Aquamacs type:
meta-- meta-x slime RETURN
ccl64
(meta key is usually mapped to option, tapping ESC before the key also works)

Steps for installing Quicklisp

➜ cd ~
➜ curl -O http://beta.quicklisp.org/quicklisp.lisp
➜ sbcl --load quicklisp.lisp  # replace sbcl with ccl64 if using Clozure CL
* (quicklisp-quickstart:install)
; Try to install some package (CL-PPCRE is a regexp library written by Edi Weitz):
* (ql:quickload "cl-ppcre")
; Search for available libraries:
* (ql:system-apropos "vecto")
; Add Quicklisp to your Lisp's init file:
* (ql:add-to-init-file)
; Done
* (quit)