22858 total geeks with 3297 solutions
Recent challengers:
best bread maker
 Welcome, you are an anonymous user! [register] [login] Get a yourname@osix.net email address 

Articles

GEEK

User's box
Username:
Password:

Forgot password?
New account

Shoutbox
sefo
anilg, new comments are deleted automaticall y because of some abuse recently
anilg
this is plain wierd. I submitted comments twice to article 950, and they dont seem to be there. Something wrong with the comment code?
CodeX
shout-boxes in general are old + the staff thing happened to everyone after an issue 2 months ago
anilg
/me is no longer staff :(
anilg
Also, osix's shoutbox predated twitter. Heh.

Donate
Donate and help us fund new challenges
Donate!
Due Date: Jul 31
July Goal: $40.00
Gross: $0.00
Net Balance: $0.00
Left to go: $40.00
Contributors


News Feeds
The Register
UK.gov sticks to IE
6 cos it"s more
"cost effective",
innit
T-Mobile UK pumps
out the iPhone 4
Polaroid 300
instant print
camera
NatWest dumps O2
Money
YouTube ups video
time limit
Alleged expenses
fiddlers to face
justice
Nude trampolinist
bounces free from
court
Nexus One phone
rockets to 28,000ft
UK.gov drops £6m on
Google
Fake Firefox update
used to sling
scareware
Slashdot
British ISPs Favour
Well-Connected
Customers
"Bizarre"
Nanobubbles Found
In Strained
Graphene
1-in-1,000 Chance
of Asteroid Impact
In
...
2182?
2 Chinese ISPs
Serve 20% of World
Broadband Users
World"s Fastest
Hybrid OK"d For
Production
Sometimes It"s OK
To Steal My Games
Thermoelectrics
Could Let You Feel
the Heat In Games
KDE SC 4.7 May Use
OpenGL 3 For
Compositing
Perl 6, Early, With
Rakudo Star
Internal Costs Per
Gigabyte —
What Do You Pay?
Article viewer

Getting started in Common Lisp on Ubuntu.



Written by:GrayMagiker
Published by:Nightscript
Published on:2008-12-14 20:56:13
Topic:Common Lisp
Search OSI about Common Lisp.More articles by GrayMagiker.
 viewed 15631 times send this article printer friendly

Digg this!
    Rate this article :
This article will explain the necessary steps to install a common
lisp on your Ubuntu machine. By the end of this article you should be able to write some simple Common Lisp programs. It uses
GNU CLISP and is mainly geared
toward Ubuntu, though should work on Debian.

Install Ubuntu
The first step is to install Ubuntu (or other Debian based Linux).
For this example I am using Ubuntu 8.04LTS. The steps are fairly
standard, but I have not tested them on any other system. For help on
installing Ubuntu please check out the

Documentation


Install CLISP from apt
Next, you need to install a lisp. There are various versions of
common lisp, and each has it's strengths. I have chosen to use
GNU CLISP, however
SBCL is also available in apt.

Get CLISP in the normal way from apt with the command:
sudo apt-get install clisp

Enter your password, and confirm the install.

Test that clisp is working
Now you should have clisp installed. Test it by trying to get to the
clisp prompt.

Enter the following command at the terminal:
clisp


You should see something like this

test@ubuntu:~$ clisp
i i i i i i i ooooo o ooooooo ooooo ooooo
I I I I I I I 8 8 8 8 8 o 8 8
I \ `+' / I 8 8 8 8 8 8
\ `-+-' / 8 8 8 ooooo 8oooo
`-__|__-' 8 8 8 8 8
| 8 o 8 8 o 8 8
------+------ ooooo 8oooooo ooo8ooo ooooo 8

Welcome to GNU CLISP 2.42 (2007-10-16) <http://clisp.cons.org/>

Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
Copyright (c) Bruno Haible, Sam Steingold 1999-2000
Copyright (c) Sam Steingold, Bruno Haible 2001-2007

Type :h and hit Enter for context help.

[1]>


You are now at the lisp REPL (Read Eval Print Loop).

To return to the command line, type
(quit)


Congratulations, you have just installed a common lisp on your Ubuntu
machine. While you can now follow along with some of the articles on
OSIX like this one http://osix.net/modules/article/?id=673
you don't have the advantage of syntax highlighting, or anything fancy
like that. But don't worry, keep reading and I'll show you how to get
syntax highlighting, and a real interactive environment.

Install Emacs and SLIME

Now we need to install Emacs. Emacs is written in it's own version of
lisp (called elisp), and has a lot of built in support for editing
lisp code in files. Even some die hard vi fans edit lisp code in
Emacs. We are also going to install an optional component for Emacs,
called slime, which provides even more support for interacting with
the lisp process.

Both are available via apt, so...
sudo apt-get install emacs slime


Configure Emacs
Now before you fire up Emacs, we have to configure some settings so
that Emacs knows where to find our lisp install. Actually even if you
did start Emacs, you could change these things while it was running
but that is a bit more complicated then we want to get right at the
moment.

First we need to make a directory for slime to use, and for us to put
any extensions that we install for it latter.

mkdir ~/.slime


Next we need to tell Emacs where that directory is, and how to start
clisp. Put the following code into a file named `.emacs' located in
your home directory:

;;; Lisp (SLIME) interaction
(setq inferior-lisp-program "clisp")
(add-to-list 'load-path "~/.slime")
(require 'slime)
(slime-setup)


The first line of this code is a comment, explaining what the other
lines do. (good practice).

The second line of the above code tells Emacs the command to use to
start a lisp session. This isn't necessary to run e-macs, but it is
if we want to get a interactive session going. You could change
"clisp" to "sbcl" if you wanted to use SBCL. You could even switch
back and forth to test your code in each one.

The third line tells Emacs where to find the slime directory that we
created for it. I don't know what this directory is for, but it is
recommended by the slime manual, so I'd put it in.

The next two lines tell Emacs to make slime ready to run every time it
starts up. Slime will not start every time you start Emacs, but it
will be ready at a moment's notice to start.

Add some simple customizations to Emacs
Adding the following lines to your `.emacs' file is not necessary,
but I find them to be useful.

The first one tells Emacs to enable syntax highlighting whenever it
can.

The second one tells Emacs to highlight the opening and closing
parenthesis when your cursor is over the other one. This is useful
for lisp as parenthesis are very common.

The third and forth make it so every time you hit return while editing lisp code
the next line is automatically indented correctly.
(global-font-lock-mode t)
(show-paren-mode 1)
(add-hook 'lisp-mode-hook '(lambda ()
      (local-set-key (kbd "RET") 'newline-and-indent)))


You can add any of these lines, or none of them, or only some of
them. The only exception is lines 3 and 4 must go together.



REPL, v2.0

Now all that remains is to start up Emacs, and get to writing lisp
code. For some reason Emacs does not place an entry in the
application menu when you install it. You can start it by typing
`emacs &' at the terminal. the `&' after emacs makes it run in the
background so you can enter other commands at the terminal. You can
make an launcher for Emacs on the your Gnome-panel in the standard
way. See
https://help.ubuntu.com/7.04/user-guide/C/launchers.html
for details.

Once you start Emacs you will see the welcome screen. From here it
may not be obvious what to do to start writing some lisp code, so I
will walk you through how I like to use Emacs to write lisp code.

First, some conventions: In Emacs, a lot of things are done via "key
chords" which is a fancy way of saying shortcut keys. If a line
connects two keys, they are to be pressed at the same time. Otherwise
they are to be pressed one after the other. `C-' means the control
key, and `M-' means the 'meta' key, which is usually the alt key.

eg "C-x C-f" means to press the control key and the 'x' key at the
same time. Then release them. Then press the control key and the 'f'
key at the same time. For commands like this, you can leave the
control key pressed if you'd like.

To start slime, and get to a REPL like the one we saw at he beginning
of this article, press M-x and then type the word 'slime' without
quotes. Notice that this appears at the bottom of the screen. Now
press enter.

At this point, a lot of stuff will happen and text will fly across the
screen. Don't worry, this is just Emacs setting up clisp to talk to
it.

After it is all done, you should see something like
This


This REPL is exactly like the one we had at the beginning of this
article, and you can do all the same things with it. You might ask
yourself why, then, did we go through all that trouble? Well, this
REPL is more helpful than the other one. For one, it automatically
indents your code when you press the enter key. For another, when you
are typing a function, down at the bottom of the screen it will show
you what arguments that function takes. That is kind of useful, but
there is another advantage to using slime as well.

Saving code in files

Up until now, I have not told you how to edit source code files with
lisp code in them. This is because lisp is very much about
interactive programing, and the REPL is the main way that this is
accomplished. However, interactive programing does not mean you can't
write your code in a separate file.

In Emacs, to open a file press C-x C-f. Then type the name of the
file. Alternatively you can use the open or new buttons on the tool
bar or from the file menu.

If you want Emacs to automatically do lisp highlighting, then name the
file with a .lisp extension. Or name it anything you want, and do the
following M-x and type `slime-mode' M-x and type `lisp-mode'.

If you start slime before you open the file, slime is still running.
Click on the buffers menu at the top of the Emacs window and go to
'*slime-repl clisp*' to get to it. Now to split the window to see
both at the same time, press C-x 2 to split the window horizontally or
C-x 3 to split the window vertically.

You can send code from the file you are editing to the REPL with lisp
shortcut keys. This is the true advantage of using an editing
environment like Emacs. The following short cut keys will get you
started.


C-c C-k slime-compile-and-load-file
Compile and load the current buffer’s source file.
C-c M-k slime-compile-file
Compile (but don’t load) the current buffer’s source file.
C-c C-c slime-compile-defun
Compile the top-level form at point.



The inevitable error
When you are running a program, you will almost certainly have an
error. The way in which the REPL loop deals with errors is different
from most compilers and interpreters. It allows you to inspect the
running program at the point of an error, basically it has a built in
debugger.

How to effectively use the debugger is a topic for another article.
However, if you run something at the REPL and get thrown to the
debugger read the first message, and it will give some clue as to what
went wrong. Then, to return to the REPL type `q' and the debugger
will exit.

Hack the good hack
So now you have a full lisp editing environment set up, and are ready
to start hacking lisp code.

So where to from here? There are lots of resources on the web, bellow
are a few starting with other articles right here on OSIX



Did you like this article? There are hundreds more.

Comments:
Anonymous
2009-01-15 10:00:18
Thank-you very much. This really got me started.
Anonymous
2009-04-17 19:42:23
Great article, really useful for me !
Thanks :)
Anonymous
2009-04-22 08:48:50
Thank You very much! Now it works. I wish, I had found this document a few hours earlier.
flash game
Anonymous
2009-04-24 17:33:52
Your explanation is simply super. It deserves a prize.

Thanks much.
Anonymous
2009-05-28 10:14:19
Thanks. Can you tell me that where exactly ".emacs" file is located? I cant find it in Home directory. I am on Ubuntu 8.10
Anonymous
2009-05-28 13:17:30
The last comment - you have to make that file yourself.
Thanks for this. It seems insanely hard to set up lisp for a newbie!! Some kind of initiative test perhaps? If you can't work it out, lisp isn't for you...
Anonymous
2009-06-12 21:00:19
This was very useful for me. Tnx very much! :)
Anonymous
2009-07-31 21:16:02
Very useful article. Many thanks :)
Anonymous
2009-08-07 02:10:02
This really got me started.Thank You very much!
buy drugs
Anonymous
2009-08-16 18:09:27
i am now ready to hack the good hack, armed with the power of emacs ;)
Anonymous
2009-08-21 20:09:26
Thanks:) With yours help I can start Lisp hacking:)
Anonymous
2009-09-10 02:27:56
Great job! Made the difference between me starting this adventure and giving up and giving up before I even got going. Thank you very much.
Anonymous
2009-11-29 07:38:03
awesome(est) article ever :) got me up and running in no-time.

(Thanks-a-ton writer)
;-)
Anonymous
2010-01-17 04:35:48

Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which we all need, thanks for all the enthusiasm to offer such helpful information here.

Movers Brooklyn
Anonymous
2010-01-17 04:36:11

I admit, I have not been on this webpage in a long time... however it was another joy to see It is such an important topic and ignored by so many, even professionals. I thank you to help making people more aware of possible issues.
Great stuff as usual.
International Foods Online
JamesPaul
2010-01-18 16:16:26

I am happy to find this post very useful for me, as it contains lot of information. I always prefer to read the quality content and this thing I found in you post. Thanks for sharing.

new york bus charter
Anonymous
2010-01-19 07:33:11
http://www.bagscabin.com/mulberry bags
Anonymous
2010-02-16 04:27:11
http://shubuntu.blogspot.com superb tutorial. It got me working. thanks a lot.
Anonymous
2010-02-27 16:58:46
All the world's latest and most authoritative website with all kinds of uniforms. We are recognized worldwide network of sales jersey website. Here you can choose a variety of uniforms such as MLB jerseys, NFL jerseys, NHL jerseys and NBA jerseys. Professional security identification products with credit guarantee, first-class quality and reasonable prices!
--Lin Guowang
Anonymously add a comment: (or register here)
(registration is really fast and we send you no spam)
BB Code is enabled.
Captcha Number:



     
Your Ad Here
 
Copyright Open Source Institute, 2006