Re: best environment for learning Lisp?
- From: Giorgos Keramidas <keramida@xxxxxxxxxxxxxxx>
- Date: Tue, 30 Jun 2009 20:43:25 +0300
On Mon, 29 Jun 2009 09:51:05 -0700 (PDT), ccc31807 <cartercc@xxxxxxxxx> wrote:
On Jun 29, 12:19 pm, Alberto Riva <a...@xxxxxxxxxxxxxx> wrote:
and continue to be frustrated by the environment.
What exactly is it that frustrates you?
The basic stuff, like,
- how do you write a file?
Start with:
(describe 'with-open-file)
The ``Practical Common Lisp'' book includes a very good section about
opening files for reading and writing, including such handy details
like:
* How to read a single byte.
* How to loop reading bytes until end-of-file.
* How to read many bytes in one operation, storing the data you read
in a vector of bytes.
* How to write one or multiple bytes.
- how do you save a file?
There are two levels of `file saving' when you are working in an
environment like SLIME or an IDE:
* How to save the file I am editing now in the IDE.
* How to write code that opens a file for writing, send some data to
the output file, and close it.
- how do you compile a file?
That's easy. Just type in your Lisp prompt:
(compile-file "~/lisp/filename")
This produces a "fast load" file (fasl) that you can load later, and
returns the pathname of the fasl bytecode file:
bash$ cat foo.lisp
(defun hello-world ()
(princ "Hello world"))
bash$ sbcl
* (compile-file "foo.lisp")
; compiling file "/home/keramida/foo.lisp" (written 30 JUN 2009 08:31:57
PM):
; compiling (DEFUN HELLO-WORLD ...)
; /home/keramida/foo.fasl written
; compilation finished in 0:00:00.121
#P"/home/keramida/foo.fasl"
NIL
NIL
You can load the "foo.fasl" file then:
* (load "foo.fasl")
T
* (hello-world)
Hello world
"Hello world"
*
You can also combine both steps with:
* (load (compile-file "foo.lisp"))
; compiling file "/home/keramida/foo.lisp" (written 30 JUN 2009 08:31:57
PM):
; compiling (DEFUN HELLO-WORLD ...)
; /home/keramida/foo.fasl written
; compilation finished in 0:00:00.039
T
- how do you run a script?
- how do you recover from an errir?
Lisp includes an extensive system of conditions, errors, handlers and
restarts. It is far more elaborate than any other system I have seen,
but it also takes a bit of reading to get used to the way it works.
The ``Practical Common Lisp'' book describes a *lot* of the mechanisms
you can use to handle errors, or other sorts of exceptional conditions.
It will help a lot if you read the relevant bits from the book :)
I still don't know how to write and save a file in SLIME, although I
have figured out how to compile, load, and run a script in SLIME.
However, when my script hangs, all I know how to do is kill the
process and start a new one, which takes time and frustrates the heck
out of me.
Most of the scripting languages in wide use today favor a sort of
programming that is a bit un-Lispy, using a repetitive cycle of edit,
save, run script, stare at debugging output, repeat. Lisp supports that
sort of programming too, as you have found out, but you are missing out
a *lot* of its power if you have to restart every time something odd
happens.
Most of the power of having a full Lisp at your user-interaction prompt
comes from a different sort of programming: an incremental way of ``REPL
sessions''. Instead of saving a short script and running Lisp with the
script as input, you directly enter forms at the REPL prompt and watch
for ``interesting'' things that happen as you define, redefine, extend
and experiment with the code already loaded in your Lisp image.
This is a departure from the usual cycle of edit, save, compile, run,
look at debugging output, repeat. It may seem a bit ``alien'' at first,
but it's worth trying. It may seem quite useful after a while :)
.
- Follow-Ups:
- Re: best environment for learning Lisp?
- From: ccc31807
- Re: best environment for learning Lisp?
- From: Rob Warnock
- Re: best environment for learning Lisp?
- Next by Date: Re: a step into the lisp world
- Next by thread: Re: best environment for learning Lisp?
- Index(es):
Relevant Pages
|