From: Carlo Capocasa
Subject: How To Learn LIsp (rev2)
Date: 
Message-ID: <fcsoml$qa8$1@registered.motzarella.org>
I did another iteration of 'How To Learn Lisp' and I tried to make
it friendlier, incorporating some what I learned from those of you
disagreed with me, those of you who agreed with me, and those of you
who said something completely unrelated.

I also embedded some of the data I gathered on-line in the meantime.

I hope I made some progress. Do you think so?

Carlo

--

HOW TO LEARN LISP

Step 1: Get ready to play

I'm new to this fantastic new language called Lisp(1). I heard once
that the best person to teach someone new is someone new, and I've
decided to put that idea to the test. It makes sense: being new puts
you in a unique perspective where understanding someone new takes
very little effort, while as an expert you've automated all the tiny
tasks that make up a skill so much that you don't think they're even
worth mentioning. So here, from me to you, my experience learning
Lisp in 2007.

If you believe anyone who has worked with Lisp for a long time, they
will immediately tell you it works miracles. I have used it for such
a short time, and I already tend to agree, and knowing I have barely
scratched the surface is one of the most exciting thoughts I ever
put my mind on.

Some of the things that set Lisp apart, even at the very beginners
level, are these:

* It encourages functional programming. Functional programming is
  the equivalent of 'laisser faire' leadership: Instead of marching
  into each function and barking orders, you draw out what you need
  of each function implicitly and do what you need with the data in
  your main loop. This leads to much more organic, natural and
  beautiful programming.
* It uses a much more consistent and simple syntax than most
  languages, which make it easier on the eyes and mind. This also
  enables its most intriguing feature:
* Lisp programming is so consistent it can be done by a machine.
  This can save immense amounts of work on repetitive programming
  tasks and enable others that wouldn't be possible without it.
* Lisp offers you the abilitiy to change and extend the language
  itself, often in ways that let you write language that creates
  language over multiple layers.
* Lisp bridges the gap between programming and math

Before you can really start playing with all that programming and
beauty and power, you need to do something ugly: download and
install a Lisp implementation. You know you've succeeded when you're
greeted with something that says Lisp and what looks like a shell.
This shell is your gateway to the full power that is Lisp.

Here are some places you can go to get a full fledged Lisp
implementation:

http://sbcl.sourceforge.net/platform-table.html
http://snipurl.com/download_clisp

If you are using linux, you might want to have a look around for
sbcl, ecl or clisp in your package manager.

At this point, it really doesn't matter which Lisp you chose, just
pick one! You can be more selective later, when you get to learn
more about their respective areas of usefulness. This is possible
because they all follow a standard called 'Common Lisp', which has a
reputation of being the most practical of the current Lisp dialects.

Once you've got it downloaded you will find an executable called
sbcl, ecl, clisp or similar. Run it to be greeted with the mentioned
lisp prompt. At this point, you can start hacking away in Lisp's
famous interactive mode. Try entering this (with the quotes):

"Hello, World!"

and be greeted by your first Lisp program.

You can already do lots of interesting stuff from here, but before
you play with that, you might want to make your interface more
usable: SBCL and ECL don't help you very much with editing, so
working with the prompt as it is can be quite painful.

You can alleviate that by installing a utility that will give you
all the powerful editing features you might have grown to expect
from a modern shell: Command history and autocompletion. Enter
rlwrap. It seems to be Unix only at this point, so if you're using a
different OS you might want to use CLISP for now, which has many of
the features built in. You can install it with your package manager
or build it by hand.

Once rlwrap is installed, here is how to configure it for use
with Lisp prompts:

Enter this code into your ~/.bashrc:

alias sbcl="rlwrap -b \$BREAK_CHARS sbcl"

Then you can create a file called ~/.sbcl_completions, and enter the
following code into it:

(with-open-file (!!!-stream "~/cmucl_completions"
                              :direction :output
                              :if-exists :supersede)
(let ((!!!-seen (make-hash-table :size 6000 :test #'equal))
  (!!!-cl-package (find-package "CL"))
  (!!!-cl-user-package (find-package "CL-USER")))
  (loop for !!!-package in (list-all-packages)
    do (let ((!!!-prefixes
      (if (or (eq !!!-package !!!-cl-package)
        (eq !!!-package !!!-cl-user-package))
          (list "")
          (mapcar #'(lambda (!!!-prefix)
            (concatenate 'string
              (string-downcase !!!-prefix)
              ":"))
            (if (package-nicknames !!!-package)
              (package-nicknames !!!-package)
              (list (package-name !!!-package)))))))
(loop for !!!-symbol being the symbols of !!!-package
  for !!!-symbol-name = (symbol-name !!!-symbol)
  when (or (eq (nth-value 1
  (find-symbol !!!-symbol-name
    !!!-package))
  :external)
  (eq !!!-package !!!-cl-user-package))
    do (loop for !!!-prefix in !!!-prefixes
        do (let ((!!!-completion
          (format nil
                  "~A~A~%"
                  !!!-prefix
                  (string-downcase !!!-symbol))))
(unless (or (gethash !!!-completion !!!-seen)
  (string= "!!!-"
    !!!-symbol-name
    :end2 (min
    (length !!!-symbol-name)
      4)))
    (setf (gethash !!!-completion !!!-seen)
      t)
    (princ !!!-completion !!!-stream)))))))))


At this point, you can read just about any lisp book and start
pasting the example code into your running Lisp shell and see what
it does. Here is a great place to start:

http://franz.com/support/documentation/8.1/ansicl/ansicl.htm

If you want to look up something on the way, this is a great
reference:

http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/index.html

Please have a look at the link collection at the bottom for more
useful books.

At some point, you will want to save some of your work to a file.
You can use pretty much any text editor, although a bracket matching
feature is almost essential. To run your program, you can type the
following into your terminal:

(load "something")

This will load "something.lisp" in the same directory you started
your lisp shell from. It has exactly the same effect as if you had
pasted everything in the file into the terminal. You can even write
these load statements into a file itself, which illustrates how
flexible and open Lisp is to use.

You can also start Lisp and automatically load a file by entering
one of the following into a terminal.

sbcl --load something.lisp
ecl -load something.lisp
clisp -i something.lisp

You can also go and compile a program into something that's easier
to distribute to users; here is one area where Lisp implementations
differ. Most require you the complete lisp environment into your
executable, which can be a bit clunky. For example, you can type the
following into your SBCL terminal:

(defun hello()
  (format t "Hello, World!~%")
  (quit))
(sb-ext:save-lisp-and-die "hello" :executable t
  :toplevel 'hello)

This will give you a freely distributable Hello, World! program, but
it will measure 25 megabytes. The bigger your application is, the
more features you would have used anyway, the less this will matter.

An alternative approach is that of CLISP, which compiles to
bytecode. It renders core images that are quite a bit smaller.

(defun hello()
  (format t "Hello, World!~%")
  (quit))
(ext:saveinitmem "hello" :executable t
  :quiet t :init-function 'hello)

This gives you 4.5 megabytes.

A third option is ECL, which first translates your LISP to regular C
code, and then uses the ubiquitous GNU C compiler to compile it to
machine code. My guess is that this approach will gain rapidly
because it allows the powerful LISP language to create the code the
entire Unix world is based upon. In other words, instead of writing
a program in Lisp, you are using Lisp to automate writing a program
in C. You can and even use inline C to improve the speed of
bottlenecks during profiling.

Please save the following into a text file called helloecl.lisp:

(format t "Hello, World!~%")
(quit)

Then, open up an ecl shell and enter the following:

(compile-file "helloecl.lisp" :system-p t)
(c:build-program "hello" :lisp-files '("helloecl.o"))

This yields a properly small 28 kilobyte Hello, World!, but you do
have to distribute it together with the the ecl runtime library,
which measures around 1.5 megabytes.

Now that you have the power to bring your software to other users,
you might just feel inspired enough to dive right in and write
something. I would recommend starting with a small tool for yourself
that you will find useful immediately.

Doing this brings you directly from the how to the why of
programming: Creating something useful. If you build on your useful
little program and keep every little step you add useful, you will
probably end up with something rather good. You might even feel
driven to give it away or run it as a web service.

Be warned, however. This could have the side effects of making you
rather well-known, or even earn you money. And only you can decide
if you want that.

CREDITS

Many thanks to:

  Everyone involved in the creation of math,
  computing, Unix, Lisp and the Internet.

  Richard Stallman for pioneering Free Software

  Paul Graham for making me want to learn Lisp

  Edi Weitz for the rlwrap instructions

  Everyone on the comp.lang.lisp newsgroup for
  being helpful and kind

  You, for reading

--
rev. 0.02

From: Dimiter "malkia" Stanev
Subject: Re: How To Learn LIsp (rev2)
Date: 
Message-ID: <5ledfcF7n4l2U1@mid.individual.net>
>   Edi Weitz for the rlwrap instructions

I hope you would come to a point, where you would thank Edi for more 
than that.
From: Carlo Capocasa
Subject: Re: How To Learn LIsp (rev2)
Date: 
Message-ID: <fcsp26$qi9$1@registered.motzarella.org>
And the footnote has escaped me again. This probably means that I
have to find a funnier opening sentence.

(1) Like most fantastic new things, Lisp has been around for a quite
while.
From: Slobodan Blazeski
Subject: Re: How To Learn LIsp (rev2)
Date: 
Message-ID: <1190274092.134682.226250@o80g2000hse.googlegroups.com>
On Sep 20, 5:16 am, Carlo Capocasa <······@carlocapocasa.com> wrote:
> I did another iteration of 'How To Learn Lisp' and I tried to make
> it friendlier, incorporating some what I learned from those of you
> disagreed with me, those of you who agreed with me, and those of you
> who said something completely unrelated.
>
> I also embedded some of the data I gathered on-line in the meantime.
>
> I hope I made some progress. Do you think so?
>
> Carlo

You made a lot of progress and officially become a Youngling. Now shut
up and continue lisping ,and you'll  become a Padawan , and some day
even an Jedi.
From: Pascal Costanza
Subject: Re: How To Learn LIsp (rev2)
Date: 
Message-ID: <5lehu3F7s35kU1@mid.individual.net>
Carlo Capocasa wrote:
> I did another iteration of 'How To Learn Lisp' and I tried to make
> it friendlier, incorporating some what I learned from those of you
> disagreed with me, those of you who agreed with me, and those of you
> who said something completely unrelated.

I have written a guide to Lisp some time ago which you may find 
interesting. It contains a couple of links to other material as well.

See http://p-cos.net/lisp/guide.html



Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: Carlo Capocasa
Subject: Re: How To Learn LIsp (rev2)
Date: 
Message-ID: <fcu4pm$3bd$1@registered.motzarella.org>
> See http://p-cos.net/lisp/guide.html

(foo bar goo)

I like that one :)

Carlo