This is how you start programming in Lisp.
A series of kind suggestions from the helpers of #lisp
This page is my personal suggestion for how a new user should go about
setting up their environment to learn Common Lisp, what tutorials to
investigate, and where they should seek help and guidance. It's also a
tutorial on how to pick a configuration that other people are going to
be able to help you with. What this boils down to is whether you care
if you get laughed at instead of helped. If you do care, follow this
guide.
If you do not follow these instructions, you will receive much less
helpful advice from the regulars of #lisp. If you deviate too much,
you will likely be ignored. Therefore, if you actually want help,
follow these directions.
Picking a Lisp implementation
Note for Windows users: If you're running Windows and don't
have the option of using some kind of UNIX-like, the best resource for
Common Lisp will be Bill
Clementson's Blog. In particular this
entry is a good guide to setting up with various CL
implementations on Win32. My advice is to try CLISP and not the others
unless you know you are interested in a commercial product. Of course,
if you're not running Windows, there are higher quality
implementations available, which I'll focus on here.
There is a lot of variety in Common Lisp implementations. If you are
just starting with Common Lisp, it can be confusing to pick one. Many
times people pick the wrong ones to start with because they go
searching for a GNU lisp. These are the lisp implementations you
should choose.
- Steel Bank Common Lisp (also
known as SBCL), a multiplatform native compiling Common Lisp
implementation. SBCL currently runs on many systems, including x86
Linux / FreeBSD / NetBSD / OpenBSD, SPARC / Solaris, and PowerPC / OS
X / Linux. This is a very good choice to start with, as there are many
SBCL developers on #lisp.
- CMU Common Lisp (also
CMUCL) is the Lisp that SBCL was forked from. It doesn't run on as
many platforms but has some different features than SBCL. There are
several CMUCL developers on #lisp. This is also a very good choice.
- OpenMCL, a native
compiling Common Lisp for PowerPC Linux and OS X. A very good choice
for Mac users and used by many #lisp regulars.
- If you're using Windows, the best option is honestly to install
Linux. The best free Common Lisp implementations aren't yet available
under Windows. SBCL and CMUCL ports to Windows are underway, so
hopefully this shouldn't be the best option forever. It's a better
idea to get a copy of Linux and learn how to use it, since most CL
development goes on under some kind of UNIX-like system. For more
information on CL under Windows, check Bill
Clementson's Blog.
N.B. Only free-as-in-libre
lisps are considered here, as few of the active #lisp helpers use a
commercial lisp, while many help develop free ones. If you want a
commercial implementation, there
are many available, and they all have
support resources for new users that you should consult in event of
trouble.
There are other Common Lisp implementations out there. Using a free
implementation other than SBCL, CMUCL, or OpenMCL to get started will
likely leave you with a bad impression of Common Lisp. Don't Do
It. Learning Scheme and thinking that it's the same as Common Lisp is
also a big mistake. Don't Do That Either.
Bottom line: you want SBCL, CMUCL, or OpenMCL.
Getting a development environment
There is only one development environment that is recommended for free
Common Lisps. It is called SLIME, and it is implemented as
a mode for Emacs. Many people say "I don't use Emacs; can't I use vi /
eclipse / whatever wonky editor?". The answer is "no". You can't
easily write Lisp in any editor but an Emacs-like one, and the best
option for an Emacs-like editor is Emacs or XEmacs. Using a plain text
editor without any runtime connection to your Lisp implementation just
because you think you prefer its keybindings is stupid and
self-defeating.
"I'd like to learn Russian but I have no time to memorize this funny alphabet." - cliini
To install SLIME, follow the directions to obtain the latest version,
and then add these lines to a file called .emacs in your home directory:
(add-to-list 'load-path "/where/you/put/slime")
(require 'slime)
(setq inferior-lisp-program "yourlisp")
(add-hook 'lisp-mode-hook (lambda () (slime-mode t)
(local-set-key "\r" 'newline-and-indent)
(setq lisp-indent-function 'common-lisp-indent-function)
(setq indent-tabs-mode nil)))
Replace "/where/you/put/slime" with the path where you put
the slime directory, and "yourlisp" with one of:
- "lisp" for CMU Common Lisp
- "sbcl" for Steel Bank Common Lisp
- "openmcl" for OpenMCL
When you want to start SLIME, hold down the Alt key (either Option or
Meta on a Mac, depending on your emacs configuration) and hit the
x key. Your cursor should be on the last line of the
screen. Type slime and press enter. SLIME should start in a
few minutes (possibly after some compiler messages flash by) and
present you with an interactive REPL. From there you're ready to start
using Lisp.
Bottom line: SLIME is the only free development environment for Common Lisp, and it only runs under Emacs. Learn to use it.
Getting a tutorial
If you picked SBCL (a good choice to start with), there is a short
tutorial which will help you set it up as your development
environment. Even if you didn't, reading it anyway might be useful.
- According
To..., a short introduction to setting up SBCL and SLIME for new
CL users.
There are several well written books out there on Common Lisp. If you
are just getting started with Lisp, the best text to use would be
Practical Common Lisp:
- Practical Common
Lisp by Peter Seibel. This is a good introduction to real-life
Common Lisp programming. It is available both in hardcopy and as a
full online text.
Some other texts that are often recommended are:
There are many other texts out there, but many apply to pre-ANSI
Common Lisp. Chances are you will be happiest with these texts, even
if you must pay to purchase a copy (gasp!).
Bottom Line: pick a good book and read it, cover to cover.
Other Things to Remember
If you're coming from a C-like language, you will be tempted to put
individual closing parentheses on their own lines. Don't. Put
them all together on the same line, and use the Emacs S-Expression
editing commands to work with your code.
Let Emacs indent your source code. It will intelligently line up
S-Expressions into a format which is readable and which most other
people are accustomed to. Emacs can do this automatically for you when
you hit the Tab key on a line.
Other Resources
Lisp is a language with a fifty-year history. Because of that, there's
a lot of old crap out there on the Internet for Google to find. If you
want sensible resources on CL, I'd recommend starting from the
following pages:
- CLiki, a Wiki in Common
Lisp for free CL resources.
- common-lisp.net, a
hosting service for Common Lisp open source projects.
- Planet Lisp, a blog
aggregator for Lisp-related blogs.
- The
Common Lisp HyperSpec, also known as CLHS. The definitive guide to
the ANSI Common Lisp language. Use it when you don't know what a
function does.
- Lisppaste, a
service for pasting a section of text where others can get at it. If
someone else is helping you in #lisp, paste sections of code there and
select the #lisp channel. If you want to display it elsewhere, paste
with the "None" channel and select the Common Lisp colorizing mode.
- Google. Use it.
Final Thought
Follow these directions or risk our wrath, or at least unsympathetic
attitudes!
An officially sanctioned product of the #lisp Yabos.