Re: Lisp Beginner question

From: Michael Sullivan (michael_at_bcect.com)
Date: 11/29/04


Date: Mon, 29 Nov 2004 17:04:34 -0500

Pascal Bourguignon <spam@mouse-potato.com> wrote:
> Kenny Tilton <ktilton@nyc.rr.com> writes:

> > Hint: (numberp (car (list pi))) => t

> > The Real Problem is that all beginner examples invlove lists which are
> > generated with this mysterious syntax:

> > '(a b c)

> > ...so that they do not need to do it with this less obscure syntax:
 
> > (list 'a 'b 'c)
 
> > You probably already understand this much about symbols:
 
> > (let ((a 'b)) (print (list a 'a))) => (b a)

> > ' is short for quote, which means "do not evaluate this bad boy", so
> > 'pi is just another symbol, not the constant pi (unquoted).

> > Anyway, because you have been exposed to all these '(a b c) lists, you
> > have gotten the impression that ' is just how you make a list. It is
> > not. It is just a handy way to avoid (list 'a 'b 'c), and it works
> > because QUOTE works on lists as well as atoms.

> Yes, ' should be avoided in tutorials for newbies. Only use QUOTE.

That's not the problem at all. Using ' as an abbreviation for QUOTE
should be quite clear to any intelligent newbie, and certainly was to
me.

The details of the semantics of quote was another story. The fact that
(quote (a b c)) is equivalent to (list (quote a) (quote b) (quote c))
and NOT to (list a b c) was completely *unclear* to me when I first
started learning lisp and was a source of much confusion until I figured
this out.

A question I kept asking myself for the first few dozen hours of my lisp
experience was "How does the evaluator know when to stop evaluating?"
All the examples one sees in tutorials are of course written so that
just what we want evaluated is, and what we don't want evaluated isn't.
We get the general idea that quote is used to forestall evaluation, but
the exact details of what is and isn't forestalled by it are not usually
explained clearly. When we newbies actually start trying to write stuff
ourselves, this results in a lot of errors like the one which prompted
the OP in this thread.

IMO, a statement similar to Kenny's here which makes these semantics
clear, should be in every lisp tutorial at the moment that anyone starts
talking about lists. It would have saved me a lot of confusion, and I'm
clearly not the only one.

Michael



Relevant Pages

  • Re: newbie Q: opposite of quote
    ... (eval (quote a)) ... a first Common Lisp lesson. ... you can use lists as short as you want. ... symbols, set, setq, setf, psetq, psetf. ...
    (comp.lang.lisp)
  • Re: Xah on Lisp
    ... (quote a b c) ... The language itself (i.e. the Lisp semantics) are in no way confused. ... There was simply no quote or double-quote character, ... syntactic tree made of lists and atoms, ...
    (comp.lang.lisp)
  • Re: newbie question about quote
    ... > Hi I'm new to LISP. ... > "Quote may seem a bit of a foreign concept because few other languages ... > Can anyone give a simple example illustrating what Paul Graham means. ... However, others are evaluated differently, like symbols and lists. ...
    (comp.lang.lisp)
  • Re: the little schemer
    ... from the scheme dialect to Common Lisp (Lisp In A Box with the CLisp ... I wanted to pass this list of lists to my function firsts. ... The ' is an abbreviation for QUOTE. ...
    (comp.lang.lisp)
  • Re: [opensuse] Re: Running a program as root from desktop panel
    ... poor that I can't remember what the thread is about I can always scroll ... On other mailing lists, the system always ... I use an official Mozilla extension called "Quick Quote". ... But doesn't this sort of defeat the purpose of bottom posting? ...
    (SuSE)