Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Casting SPELs in Lisp - The Comic Book!

39 views
Skip to first unread message

drc...@gmail.com

unread,
Dec 5, 2004, 8:58:46 PM12/5/04
to
Hi fellow LISPers, I have just slaved away at a new online tutorial for
newbies or those with no previous LISP experience. (NObies? :-)

http://www.lisperati.com

(be sure to read the addendum at
http://www.lisperati.com/addendum.html
before suggesting any corrections...)

The goal of this tutorial is twofold:

1. To take a non-LISP programmer along the straightest possible line so
that he/she can appreciate some of the coolest, tastiest nuggets of
programming power that LISP has to offer.

2. To explore the idea that Macros can be taught far more easily if
they are given a different name, due to the semantic load present in
this overused term. In my tutorial, I suggest the term SPEL as a simple
synonym (replacement?) of "Macro" that offers many advantages for
reasons outlined in the following essay:

http://www.lisperati.com/no_macros.html

Any feedback is greatly appreciated!
--
Conrad Barski, M.D. (concatenate 'string "drcode@gm" "ail.com")

Kenneth Tilton

unread,
Dec 5, 2004, 11:09:43 PM12/5/04
to
In article <1102298326.4...@z14g2000cwz.googlegroups.com>,
drc...@gmail.com wrote:

That is <expletive deleted> awesome. Mind you, I am not good at reading,
so I just looked at the pictures. Brilliant. And I am glad to see QUOTE
dealt with up front, given the newbie fatality rate on that issue lately.

:)

kenny

OSU

unread,
Dec 6, 2004, 12:10:15 AM12/6/04
to
drc...@gmail.com wrote:

> 1. To take a non-LISP programmer along the straightest possible line so
> that he/she can appreciate some of the coolest, tastiest nuggets of
> programming power that LISP has to offer.

This is really good! I did some LISP, but never got around to macros (course
too short). I see what PG means by 'build the language up to the app'.. the
game-action macro was an inspired choice (so was the choice of game
programming). Glad you tackled the meaty problems, I think newbies spend
too much time mucking about with basic stuff & end up trying to do things
the non-lispy way.

cheers,
N

PS what I take away from this is that to write spels you need a basic
similarity of textual structure in the source code.. is that correct? that
ultimately it's just a source level transformation? Or is this my C macro
bias at work?

---
Nandan Bagchee
CIS / Ohio State
last...@cse.ohiodashstate.edu

Eventually the pimps and drug dealers notice that the doctors and lawyers
have switched from Cadillac to Lexus, and do the same.
-- Paul Graham

Wade Humeniuk

unread,
Dec 6, 2004, 1:08:21 AM12/6/04
to
OSU wrote:

>
> PS what I take away from this is that to write spels you need a basic
> similarity of textual structure in the source code.. is that correct? that
> ultimately it's just a source level transformation? Or is this my C macro
> bias at work?
>

It helps to keep the basic list structure when writing macros (spels).
However it is not mandatory. There are macros which can transform
things like infix math into Lisp sexpr math. Also the phrase "just
a source level transformation" is misleading. The tranformation of
a macro form to another can be done using the whole functionality of the
Lisp image. Variables can be created, context can be taken into
consideration, connections to web servers made, helper functions
can be created and compiled. Even foreign C code could be written,
compiled and dynamically linked with a Lisp's FFI. In C it is just
simple-minded substitution.

Potential Non Lispy Macro Examples:

(setf *calgary-merchants*
#!sql: select merchant.id from merchants where (merchant.city = 'Calgary');)

(publish "/echopage.html"
:virtual-host "home.com"
:mime-type "text/html"
:content
#!html: <html>
<head><title>Embedded Lisp Web Page</title></head>
<body>
You are accessing this page from !*source-ip-address*
</body>
</html>)

Wade


Pascal Bourguignon

unread,
Dec 6, 2004, 1:09:09 AM12/6/04
to
OSU <osuf...@mailite.com> writes:
> PS what I take away from this is that to write spels you need a basic
> similarity of textual structure in the source code.. is that correct? that
> ultimately it's just a source level transformation? Or is this my C macro
> bias at work?

Not exactly. That's the easiest, but you can have some other occurences.


(defmacro mul (x y)
(cond
((integerp x) ; a literal constant
(cond
((= 0 x)
0)
((= x (expt 2 (truncate (log x 2))))
`(ash y , (truncate (log x 2))))
((< x 10)
(let ((vs (gensym))(vy (gensym)))
`(let ((,vs 0)(,vy ,y)) (dotimes (i ,x) (incf s ,vy)))))
(t
`(* ,x ,y))))
(t ; a variable
`(* ,x ,y))))

(macroexpand-1 '(MUL 0 y))
==> 0, T
(macroexpand-1 '(MUL 4 y))
==> (ASH Y 2), T
(macroexpand-1 '(MUL 5 y))
==> (LET ((#:G1293623 0) (#:G1293624 Y))
(DOTIMES (I 5) (INCF S #:G1293624))), T
(macroexpand-1 '(MUL x y))
==> (* X Y), T


The textual structure of the generate source can vary quite a lot, and
still implement the same _abstraction_.

--
__Pascal Bourguignon__ http://www.informatimago.com/
The world will now reboot; don't bother saving your artefacts.

Arthur Lemmens

unread,
Dec 6, 2004, 4:33:34 AM12/6/04
to drc...@gmail.com
Conrad Barski wrote:

> Hi fellow LISPers, I have just slaved away at a new online tutorial for
> newbies or those with no previous LISP experience. (NObies? :-)
>
> http://www.lisperati.com

Very impressive!! Great drawings, clear explanation, nice example code.
It's fantastic to see something so totally different from the usual boring
explanations of quote and macros.

The only thing I missed was a "To Be Continued" line at the end. (Oh, and
there's is a misplaced "for" and a missing "-ing" in the sentence "Even for
experienced LISP programmers would have to put some thought into create a
monstrosity like this".)

It would be great if you could find a publisher for this. Maybe Markus Fix
would be interested?

--
Arthur

Markus Fix

unread,
Dec 6, 2004, 4:47:37 AM12/6/04
to
drc...@gmail.com wrote:
> Hi fellow LISPers, I have just slaved away at a new online tutorial for
> newbies or those with no previous LISP experience. (NObies? :-)
>
> http://www.lisperati.com

Beautiful! Simply amazing!

> 2. To explore the idea that Macros can be taught far more easily if
> they are given a different name, due to the semantic load present in
> this overused term. In my tutorial, I suggest the term SPEL as a simple
> synonym (replacement?) of "Macro" that offers many advantages for
> reasons outlined in the following essay:

SPEL is certainly closer to the truth about Lisp macros. A SPEL enlarges
your active vocabulary, but it drains your Mana during debugging. Very appropriate.

-fix

--
------- Markus Fix http://www.bookfix.com/ --------
--------Creating the Programmer's Library----------

Lars Brinkhoff

unread,
Dec 6, 2004, 5:26:09 AM12/6/04
to
It's the "Beginning Forth" of Lisp!

--
Lars Brinkhoff, Services for Unix, Linux, GCC, HTTP
Brinkhoff Consulting http://www.brinkhoff.se/

Adam Warner

unread,
Dec 6, 2004, 6:06:03 AM12/6/04
to
Hi drcode,

> Hi fellow LISPers, I have just slaved away at a new online tutorial for
> newbies or those with no previous LISP experience. (NObies? :-)
>
> http://www.lisperati.com
>
> (be sure to read the addendum at
> http://www.lisperati.com/addendum.html before suggesting any
> corrections...)

Bravo! Extraordinary!

One more thing we left out of the code is the defparameter command
for creating global variables- Instead, we just used setf to declare
variables (which works, but is considered bad style...)

While I understand this approach within a REPL style tutorial it would be
nice to see you fix the final code: <http://www.lisperati.com/code.html>
(that is replace each top-level setf with defparameter and add a comment
to the code explaining why you did this).

Regards,
Adam

Paul Foley

unread,
Dec 6, 2004, 6:24:09 AM12/6/04
to
On 5 Dec 2004 17:58:46 -0800, drcode wrote:

> Hi fellow LISPers, I have just slaved away at a new online tutorial for
> newbies or those with no previous LISP experience. (NObies? :-)

> http://www.lisperati.com

> Any feedback is greatly appreciated!

Please substitute "Lisp" for "LISP" throughout.

[And "Allegro Common Lisp" for "Allegro LISP", I guess]

--
If that makes any sense to you, you have a big problem.
-- C. Durance, Computer Science 234
(setq reply-to
(concatenate 'string "Paul Foley " "<mycroft" '(#\@) "actrix.gen.nz>"))

Lars Brinkhoff

unread,
Dec 6, 2004, 8:52:37 AM12/6/04
to
> It's the "Beginning Forth" of Lisp!

"Starting Forth", that is.

drc...@gmail.com

unread,
Dec 6, 2004, 9:20:36 AM12/6/04
to
I'll do that!

--Conrad

drc...@gmail.com

unread,
Dec 6, 2004, 9:21:32 AM12/6/04
to
I've gotten several replies about the upcase Lisp and will make the
requisite change.

-Conrad

drc...@gmail.com

unread,
Dec 6, 2004, 9:23:12 AM12/6/04
to
good idea- I will do that!

-Conrad

drc...@gmail.com

unread,
Dec 6, 2004, 9:24:07 AM12/6/04
to
I have gotten several replies about the upcase Lisp and will make the
change.

Thanks!

--Conrad

Paolo Amoroso

unread,
Dec 6, 2004, 9:19:28 AM12/6/04
to
drc...@gmail.com writes:

> Hi fellow LISPers, I have just slaved away at a new online tutorial for
> newbies or those with no previous LISP experience. (NObies? :-)
>
> http://www.lisperati.com

Holy bit! :) By the way, "lisperati" sounds similar to "disperati",
which is the Italian for "desperate".

Thanks for the great resource,


Paolo
--
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Recommended Common Lisp libraries/tools (see also http://clrfi.alu.org):
- ASDF/ASDF-INSTALL: system building/installation
- CL-PPCRE: regular expressions
- UFFI: Foreign Function Interface

Szymon

unread,
Dec 6, 2004, 12:15:20 PM12/6/04
to
Paolo Amoroso <amo...@mclink.it> writes:

> drc...@gmail.com writes:
>
>> Hi fellow LISPers, I have just slaved away at a new online tutorial for
>> newbies or those with no previous LISP experience. (NObies? :-)
>>
>> http://www.lisperati.com
>
> Holy bit! :)

Yes, _very_ nice stuff.

> By the way, "lisperati" sounds similar to "disperati", which is the
> Italian for "desperate".

My association was with 'iluminati' or 'illuminati' :P

Regards, Szymon.

Message has been deleted

drc...@gmail.com

unread,
Dec 6, 2004, 12:41:28 PM12/6/04
to
The intention was to reference "literati" and "digerati".

Given the cult-like nature of the lisp community, I suppose
"illuminati" works as well :)

"Desperate" i suppose isn't totally unreasonable either ;)

-Conrad

Ingvar wrote:


> Szymon <r5z-u2...@o2.pl> writes:
>
> > Paolo Amoroso <amo...@mclink.it> writes:
> >
> > > drc...@gmail.com writes:
> > >
> > >> Hi fellow LISPers, I have just slaved away at a new online
tutorial for
> > >> newbies or those with no previous LISP experience. (NObies? :-)
> > >>
> > >> http://www.lisperati.com
> > >
> > > Holy bit! :)
> >
> > Yes, _very_ nice stuff.
>

> It was certainly interesting.


>
> > > By the way, "lisperati" sounds similar to "disperati", which is
the
> > > Italian for "desperate".
> >
> > My association was with 'iluminati' or 'illuminati' :P
>

> Oh? I was thinking "literati".
>
> //Ingvar
> --
> "No. Most Scandiwegians use the same algorithm as you Brits.
> "Ingvar is just a freak."
> Stig Morten Valstad, in the Monastery

Pascal Costanza

unread,
Dec 6, 2004, 1:20:37 PM12/6/04
to

Markus Fix wrote:
> drc...@gmail.com wrote:
>
>> Hi fellow LISPers, I have just slaved away at a new online tutorial for
>> newbies or those with no previous LISP experience. (NObies? :-)
>>
>> http://www.lisperati.com
>
> Beautiful! Simply amazing!

I'd like http://www.lisperati.com/different.jpg as a T-shirt. ;)


Pascal

--
The big bang way only works for god, everybody else has to use
evolution. - David Moon

Svein Ove Aas

unread,
Dec 6, 2004, 1:23:12 PM12/6/04
to
Pascal Costanza wrote:

>
> Markus Fix wrote:
>> drc...@gmail.com wrote:
>>
>>> Hi fellow LISPers, I have just slaved away at a new online tutorial for
>>> newbies or those with no previous LISP experience. (NObies? :-)
>>>
>>> http://www.lisperati.com
>>
>> Beautiful! Simply amazing!
>
> I'd like http://www.lisperati.com/different.jpg as a T-shirt. ;)
>

Ooh... t-shirty goodness...

We could probably get cafepress to do that.

Emre Sevinc

unread,
Dec 6, 2004, 2:54:07 PM12/6/04
to
drc...@gmail.com writes:

> Hi fellow LISPers, I have just slaved away at a new online tutorial for
> newbies or those with no previous LISP experience. (NObies? :-)
>
> http://www.lisperati.com
>
> (be sure to read the addendum at
> http://www.lisperati.com/addendum.html
> before suggesting any corrections...)
>

My first impression: Lovely!

My demand: I want to translate it into Turkish,
including the baloons. If you can bother yourself
to put my translations in the baloons, I can handle
the remaining work by myself. I want to introduce
Common Lisp to Turkish speaking computer community
however there are many programmers who do not know
English very well so a fancy beginner tutorial like
that one, in their mother tongue would motivate them
to learn more Common Lisp (and English as well :)

--
Emre Sevinc

eMBA Software Developer Actively engaged in:
http:www.bilgi.edu.tr http://ileriseviye.org
http://www.bilgi.edu.tr http://fazlamesai.net
Cognitive Science Student http://cazci.com
http://www.cogsci.boun.edu.tr

drc...@gmail.com

unread,
Dec 6, 2004, 2:59:21 PM12/6/04
to
If you give me the translations, I'll be glad to change the captions.
-Conrad (concatentate 'string "drcode@gm" "ail.com")

Tayssir John Gabbour

unread,
Dec 6, 2004, 3:17:35 PM12/6/04
to
Pascal Costanza wrote:
> I'd like http://www.lisperati.com/different.jpg as a T-shirt. ;)

I seriously thought about making that the picture, when I posted it on
the c2 wiki. It really doesn't seem like there are enough crazy Lisp
flamewars there right now.

There's something about that picture.


> The big bang way only works for god, everybody else has to use
> evolution. - David Moon

A quick Google didn't pick that quote up. Was that from some talk?
MfG,
#\Tayssir

drc...@gmail.com

unread,
Dec 6, 2004, 3:25:25 PM12/6/04
to
If somebody else wants to take the initiative of doing some marketing
and creating a nice website for it (i.e. more than just the generic
cafepress page), I'd be glad to take the Lisp vs. other languages motif
from the blackboard of the cartoon and make it into a more polished
design for a tshirt.
--Conrad (concatenate 'string "drcode@gm" "ail.com")

Dirk Gerrits

unread,
Dec 6, 2004, 3:26:42 PM12/6/04
to
drc...@gmail.com writes:

> Hi fellow LISPers, I have just slaved away at a new online tutorial for
> newbies or those with no previous LISP experience. (NObies? :-)
>
> http://www.lisperati.com

This is just great stuff! I don't know what more to say. :)

Just a couple of small nits:

1. The "old", pre-GAME-ACTION version of WELD does not SETF
*CHAIN-WELDED*.

2. The first line of the body of the GAME-ACTION SPEL is indented too
much.

3. Indentation is accomplished with a mixture of tabs and spaces.
People who copy & paste the code and use a tab-width different from
yours might find the indentation of the code a bit odd. I greatly
prefer the use of spaces only.

Kind regards,

Dirk Gerrits

drc...@gmail.com

unread,
Dec 6, 2004, 3:43:24 PM12/6/04
to
great feedback! I'll make those changes.

-Conrad

drc...@gmail.com

unread,
Dec 6, 2004, 3:43:44 PM12/6/04
to

Emre Sevinc

unread,
Dec 6, 2004, 4:19:25 PM12/6/04
to
drc...@gmail.com writes:

> If you give me the translations, I'll be glad to change the captions.
> -Conrad (concatentate 'string "drcode@gm" "ail.com")
>

Cool. BTW, what about the licence, copyright, etc. situation
of the text? Which one do you prefer? To publish the
Turkish translation (with Turkish baloon captions)
on your website or do you consider it be published on
some other mirror sites, too?

Pascal Costanza

unread,
Dec 6, 2004, 4:43:33 PM12/6/04
to

Tayssir John Gabbour wrote:

>>The big bang way only works for god, everybody else has to use
>>evolution. - David Moon
>
> A quick Google didn't pick that quote up. Was that from some talk?

It's from one of the "dynamic languages wizards" panels - see
http://www.ai.mit.edu/projects/dynlangs/wizards-panels.html


Pascal

--

Alex Mizrahi

unread,
Dec 6, 2004, 5:04:26 PM12/6/04
to
(message (Hello 'drc...@gmail.com)
(you :wrote :on '(5 Dec 2004 17:58:46 -0800))
(

d> http://www.lisperati.com

looks like here's a bug:

(defun walk-direction (direction)
(let ((next (assoc direction (cdr (assoc *location* *map*)))))
(cond (next (setf *location* (third next)) (look))
(t '(you cant go that way.)))))

cdr in (cdr (assoc *location* *map*)) should be cddr, as it was in
#'describe-paths

)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
(prin1 "Jane dates only Lisp programmers"))


drc...@gmail.com

unread,
Dec 6, 2004, 5:06:43 PM12/6/04
to
The text has a creative commons license (you can do whatever you want
with it, as long as you give me credit)

> To publish the
> Turkish translation (with Turkish baloon captions)
> on your website or do you consider it be published on
> some other mirror sites, too?

I'll put it on my webserver as a link on the main page- If you want to
put it on a separate site as well, mirrors are no problem.

-Conrad

drc...@gmail.com

unread,
Dec 6, 2004, 5:13:16 PM12/6/04
to
great catch! luckily, its not noticable- Still, a pretty bad mistake...
-Conrad

Raffael Cavallaro

unread,
Dec 6, 2004, 7:00:59 PM12/6/04
to
On 2004-12-06 15:25:25 -0500, drc...@gmail.com said:

> I'd be glad to take the Lisp vs. other languages motif
> from the blackboard of the cartoon and make it into a more polished
> design for a tshirt.

I think you might want to include the Lisp Wizard as well - he adds
quite a bit to that particular cartoon (IMHO, of course).

Well done all around - I thoroughly enjoyed it.

regards,

Ralph

philip...@gmail.com

unread,
Dec 6, 2004, 7:51:55 PM12/6/04
to
That's awesome!
Very creative to make the code a text adventure game. As well as
explaining the basic clearly and non-guruish-ly :)
I've already refered a freiend to it.

BTW, google groups 2 kicks butt!!!
--
Certum quod factum.
Philip Haddad

philip...@gmail.com

unread,
Dec 6, 2004, 7:52:29 PM12/6/04
to

Alex Mizrahi

unread,
Dec 6, 2004, 8:12:28 PM12/6/04
to
(message (Hello 'drc...@gmail.com)
(you :wrote :on '(6 Dec 2004 14:13:16 -0800))
(

d> great catch! luckily, its not noticable- Still, a pretty bad
d> mistake...

i think plists can decrease confusion with all this cddr, second, third..

Szymon

unread,
Dec 6, 2004, 8:46:23 PM12/6/04
to
"Alex Mizrahi" <udod...@hotmail.com> writes:

Hi.

> (message (Hello 'drc...@gmail.com)
> (you :wrote :on '(6 Dec 2004 14:13:16 -0800))
> (
>
> d> great catch! luckily, its not noticable- Still, a pretty bad
> d> mistake...
>
> i think plists can decrease confusion with all this cddr, second, third..

or maybe symbol-macros to "rename" cddr, second, third...

Btw, I think that present state is OK. Do not overkill simple things...

Regards, Szymon.

ps. I just used plists in toy-blog-code-snippet --
I'm not very impressed...
url: [ http://lisp.jogger.pl/comment.php?eid=78513 ].

William Bland

unread,
Dec 6, 2004, 11:05:17 PM12/6/04
to
On Mon, 06 Dec 2004 16:52:29 -0800, philip.haddad wrote:

> That's awesome!
> Very creative to make the code a text adventure game. As well as
> explaining the basic clearly and non-guruish-ly :)
> I've already refered a freiend to it.

Agreed, bloody fantastic! A nice gentle, humorous introduction, but with
plenty of "meat" to it. I've referred two friends to it already.

Thanks,
Bill.

drc...@gmail.com

unread,
Dec 7, 2004, 12:22:24 AM12/7/04
to
I'm afraid I have to admit that in one of the early chapters of PG's
ANSI Common Lisp (my introduction to lisp) it said that plists are a
_bad_ thing, so I never got around to learning them, even though that
was a long time ago- How pathetic is that? :)

-Conrad

William Bland

unread,
Dec 7, 2004, 12:23:33 AM12/7/04
to
Minor typo: On http://www.lisperati.com/addendum.html near the end you
have "slighlty" rather than "slightly".

Cheers,
Bill.

Antony Sequeira

unread,
Dec 7, 2004, 12:39:08 AM12/7/04
to
It looks and reads great as is.
Why introduce a new data type when not needed ?
(Same reason why you did not use dotted notation).
May be you can just add a line at the end saying you have introduced
0.01% features/power of CL in this tutorial :)
My 2c

Thanks for the fun and education.
-Antony

Pascal Costanza

unread,
Dec 7, 2004, 3:50:45 AM12/7/04
to

I don't know the exact context of this discussion, but in my experience
plists can be very handy in some cases. There are situations when they
are better than alists and vice versa, and both alists and plists can be
more efficient than hashtables when the number of associations is below
50 or 60 (on a few implementations that I have checked under Mac OS X).

However, the most straightforward data structure for newbies who know
about other languages is probably the hashtable. You don't loose much
time explaining what a hashtable is, while alists and plists require a
certain amount of handwaiving in the beginning.

I don't understand why Paul Graham and other (mostly "old") Lispers
don't like plists. (Would be interesting to know more about it.)

Peder O. Klingenberg

unread,
Dec 7, 2004, 4:08:41 AM12/7/04
to
Pascal Costanza <cost...@web.de> writes:

> I don't understand why Paul Graham and other (mostly "old") Lispers
> don't like plists. (Would be interesting to know more about it.)

I think there's plists and then there's plists. The kind of property
lists Graham talks about in "Ansi Common Lisp" (p. 134) is the plist
associated with a symbol, the second definition in the hyperspec
glossary, accessed by GET and SYMBOL-PLIST.

This kind of property list is not used much by me, at least, nor have
I seen it in use in other code I'm working with. From my experience,
I would not argue with Graham that it's more or less obsolete.

The other kind of plists - the first definition in the hyperspec,
accessed by GETF - I find rather useful. When using keywords as keys,
I can apply MAKE-INSTANCE to them, and they are easy to serialize for
communication over sockets. Turning them into hashes in PHP or
Perl is easy.

I would disagree with anyone trying to obsolete them. Fortunately,
that's not what Graham does. From a cursory glance at the index of
"Ansi Common Lisp", it doesn't seem like he mentions this kind of
plist at all.

...Peder...
--
I wish a new life awaited _me_ in some off-world colony.

Szymon

unread,
Dec 7, 2004, 8:11:51 AM12/7/04
to
pe...@news.klingenberg.no (Peder O. Klingenberg) writes:

> Pascal Costanza <cost...@web.de> writes:
>
>> I don't understand why Paul Graham and other (mostly "old") Lispers
>> don't like plists. (Would be interesting to know more about it.)

Because, 'they' (Peter Norvig (in PAIP)) do not know how to use
them. (This is _joke_ of course. See rest of this article.)

> I think there's plists and then there's plists. The kind of property
> lists Graham talks about in "Ansi Common Lisp" (p. 134) is the plist
> associated with a symbol, the second definition in the hyperspec
> glossary, accessed by GET and SYMBOL-PLIST.

Btw, I think that (very) short symbol-plists are convinient when one
need a symbol with "two values" (if second value is meant to be used
less frequently).

Instead of: (setq foo (cons 1 2))

(setq foo 1)

(setf (get 'foo :value-2) 2)


(get 'foo :value-2) ==> 2

* * *

Abtw, I found funny 'bugs' in PAIP (pages 75,76) (of course this is
greatest book ever written ;)

"Property lists have a long history in Lisp, but they are failing ouf of
favor as new alternatives such as hash tables are introduced. There are
two main reasons why property lists are avoided. First, because symbols
and their property lists are global,"

Half true (ok symbols are global, but can be interned in diffrent packages).

CL-USER> (defpackage "FOO" (:export "BAR"))
#<The FOO package, 0/8 internal, 1/2 external>

CL-USER> (defpackage "BAZ" (:export "BAR"))
#<The BAZ package, 0/8 internal, 1/2 external>

CL-USER> (setf (get 'foo:bar :value) 'foshmoo)
FOSHMOO

CL-USER> (setf (get 'baz:bar :value) 'blah)
BLAH

CL-USER> (symbol-plist 'foo:bar)
(:VALUE FOSHMOO)

CL-USER> (symbol-plist 'baz:bar)
(:VALUE BLAH)

CL-USER> (symbol-plist 'baz)
NIL

"its easy to get conflicts when trying to put together two programs that
use property lists. If two programs use the same property for diffrent
purposes, they cannot be used together."

Think about packages...

"Even if two programs use _different_ properties on the same symbols,
they will slow each other down."

Do more thinking about packages...

"Second, property lists are messy. There is no way to remove quickly
every element of a table implemented with property lists."

[ "There is no way to remove quickly every element of a table
implemented with property lists." ]

hmm...

!! CL-USER> (setf (symbol-plist 'foo:bar) nil) ; [ <---- ]
!! NIL
!!
!! CL-USER> (symbol-plist 'foo:bar)
!! NIL

If one do not want to waste conses:

(setf (symbol-plist 'symbol) (copy-list '(:a 1 :b 2 :c 3 :d 4)))
==> (:A 1 :B 2 :C 3 :D 4)

(symbol-plist 'symbol)
==> (:A 1 :B 2 :C 3 :D 4)

;; slow
(loop for i in (symbol-plist 'symbol) by #'cddr do (setf (get 'symbol i) nil))

(symbol-plist 'symbol)
==> (:A NIL :B NIL :C NIL :D NIL)

_More_ effective way:

!! (setf (symbol-plist 'symbol) (copy-list '(:a 1 :b 2 :c 3 :d 4)))
!! ==> (:A 1 :B 2 :C 3 :D 4)

!! ;; fast
!! (loop for i on (cdr (symbol-plist 'symbol)) by #'cddr do (rplaca i nil))

!! (symbol-plist 'symbol)
!! ==> (:A NIL :B NIL :C NIL :D NIL)

"In contrast, this can be done trivially with CLRHASH on hash tables,
or by setting an assotiation list to NIL." [ <---- ]

doh!

* * *

> This kind of property list is not used much by me, at least, nor have
> I seen it in use in other code I'm working with. From my experience,
> I would not argue with Graham that it's more or less obsolete.

> The other kind of plists - the first definition in the hyperspec,
> accessed by GETF - I find rather useful. When using keywords as keys,

> I can apply MAKE-INSTANCE to them,

Good idea.

My solution (overcomplicated, your is better):

(apply #'mapc (make-instance 'class-foo :init-arg-1 <> :init-arg-2 <>) foo-inits)

foo-inits: ((init-arg-1-1 init-arg-1-2 ...) (init-arg-2-1 init-arg-2-1 ...))

> and they are easy to serialize for communication over sockets.
> Turning them into hashes in PHP or Perl is easy.
>
> I would disagree with anyone trying to obsolete them. Fortunately,
> that's not what Graham does. From a cursory glance at the index of
> "Ansi Common Lisp", it doesn't seem like he mentions this kind of
> plist at all.

Regards, Szymon.

Szymon

unread,
Dec 7, 2004, 8:28:42 AM12/7/04
to
Szymon <r5z-u2...@o2.pl> writes:

> (apply #'mapc (make-instance 'class-foo :init-arg-1 <> :init-arg-2 <>) foo-inits)
>
> foo-inits: ((init-arg-1-1 init-arg-1-2 ...) (init-arg-2-1 init-arg-2-1 ...))

^^^^^^^^^^^^

((init-arg-1-1 init-arg-1-2 ...) (init-arg-2-1 init-arg-2-2 ...))

Regards, Szymon.

drc...@gmail.com

unread,
Dec 7, 2004, 9:06:59 AM12/7/04
to
will fix - conrad

Duane Rettig

unread,
Dec 7, 2004, 11:21:59 AM12/7/04
to
Pascal Costanza <cost...@web.de> writes:

> drc...@gmail.com wrote:
> > I'm afraid I have to admit that in one of the early chapters of PG's
> > ANSI Common Lisp (my introduction to lisp) it said that plists are a
> > _bad_ thing, so I never got around to learning them, even though that
> > was a long time ago- How pathetic is that? :)
>
> I don't know the exact context of this discussion, but in my
> experience plists can be very handy in some cases. There are
> situations when they are better than alists and vice versa, and both
> alists and plists can be more efficient than hashtables when the
> number of associations is below 50 or 60 (on a few implementations
> that I have checked under Mac OS X).
>
>
> However, the most straightforward data structure for newbies who know
> about other languages is probably the hashtable. You don't loose much
> time explaining what a hashtable is, while alists and plists require a
> certain amount of handwaiving in the beginning.

Alists, plists, and hash-tables are best explained as mappings of
indicators onto values. They have different characteristics which
make them useful for various circumstances.

> I don't understand why Paul Graham and other (mostly "old") Lispers
> don't like plists. (Would be interesting to know more about it.)

I don't know how others view plists, but I certainly don't view
them as obsolete. One danger of using plists on symbols is that these
tend to be global in nature, since the symbols tend to be interned.
This can lead to conflicting usages unless the indicators are chosen
wisely to not clash with other potential indicator usages from
different modules. Other than that, plists are, like alists, very
simple to use and carry less space overhead than hash-tables when
the mapping set is small. The watchword here is to be careful. Use
the appropriate tool for the job at hand.

I use both hash-tables and plists for my environments access module.
The hash-tables are for the lexical mappings, and the plists are
for the global mappings. Note that neither mapping is attached directly
to a symbol, unless in the global (null lexical) environment, and even
then there might be a mapping of non-symbolic names to values (consider,
for example, function names such as (setf foo) or, in some lisps, extended
function names like (flet foo bar), which must have their own mappings
without hanging them on symbols).

--
Duane Rettig du...@franz.com Franz Inc. http://www.franz.com/
555 12th St., Suite 1450 http://www.555citycenter.com/
Oakland, Ca. 94607 Phone: (510) 452-2000; Fax: (510) 452-0182

Pascal Costanza

unread,
Dec 7, 2004, 11:50:38 AM12/7/04
to
Duane Rettig wrote:

> Pascal Costanza <cost...@web.de> writes:
>
>>However, the most straightforward data structure for newbies who know
>>about other languages is probably the hashtable. You don't loose much
>>time explaining what a hashtable is, while alists and plists require a
>>certain amount of handwaiving in the beginning.
>
> Alists, plists, and hash-tables are best explained as mappings of
> indicators onto values. They have different characteristics which
> make them useful for various circumstances.

Of course, you're right. However, the advantage of hashtables (in my
limited experience) is, when presenting them to Lisp newbies, that they
have most probably heard of that data structure in other languages, so
you can quickly proceed with the stuff that you really want to present.
Furthermore as a side effect, this gives some people the clue that the
standard Common Lisp library is more complete than they would have thought.

>>I don't understand why Paul Graham and other (mostly "old") Lispers
>>don't like plists. (Would be interesting to know more about it.)
>
> I don't know how others view plists, but I certainly don't view
> them as obsolete.

Good. ;)

Pascal

--
Pascal Costanza University of Bonn
mailto:p...@p-cos.net Institute of Computer Science III
http://www.pascalcostanza.de Römerstr. 164, D-53117 Bonn (Germany)

Thomas Schilling

unread,
Dec 7, 2004, 1:29:56 PM12/7/04
to
Am 5 Dec 2004 17:58:46 -0800 schrieb <drc...@gmail.com>:

> http://www.lisperati.com

The Lisp Compiler is green!

http://www.lisperati.com/game_action.jpg

Oh, and I want that T-Shirt.

-ts

Peter Seibel

unread,
Dec 7, 2004, 1:47:04 PM12/7/04
to
Szymon <r5z-u2...@o2.pl> writes:

> "Second, property lists are messy. There is no way to remove quickly
> every element of a table implemented with property lists."
>
> [ "There is no way to remove quickly every element of a table
> implemented with property lists." ]
>
> hmm...
>
> !! CL-USER> (setf (symbol-plist 'foo:bar) nil) ; [ <---- ]
> !! NIL

Of course this is, in general, a bad idea since the symbol's plist is
a shared resource of any code that has access to the symbol. So one
piece of code should only remove indicators from a plist that it put
there in the first place--clobbering the whole plist may clobber other
codes' indicators that were put there for other reasons.

-Peter

--
Peter Seibel pe...@javamonkey.com

Lisp is the red pill. -- John Fraser, comp.lang.lisp

Alan Crowe

unread,
Dec 7, 2004, 4:18:08 PM12/7/04