From: Dale Bricker
Subject: Newbie question
Date: 
Message-ID: <5ooibf$2cg@usenet.rpi.edu>
Can anyone explain to me _why_ it is that if 

> (first '(c d e))

returns "c", why doesn't

> (first (rest '((ab) (c d e))))

also return "c" instead of "(c d e)" ?

Thanks!

Dale

From: Barry Margolin
Subject: Re: Newbie question
Date: 
Message-ID: <5oqa51$dav@pasilla.bbnplanet.com>
In article <··········@usenet.rpi.edu>, Dale Bricker  <·······@rpi.edu> wrote:
>Can anyone explain to me _why_ it is that if 
>
>> (first '(c d e))
>
>returns "c", why doesn't
>
>> (first (rest '((ab) (c d e))))
>
>also return "c" instead of "(c d e)" ?

Take a look at what (rest '((ab) (c d e))) returns:

((c d e))

(first '((c d e))) returns (c d e).

To get what you expect, you would use

(first (second '((a b) (c d e))))

-- 
Barry Margolin, ······@bbnplanet.com
BBN Corporation, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>
From: Hrvoje Niksic
Subject: Re: Newbie question
Date: 
Message-ID: <kigoh8udt5v.fsf@jagor.srce.hr>
Barry Margolin <······@bbnplanet.com> writes:

> Take a look at what (rest '((ab) (c d e))) returns:
[...]

I find it that Lisp beginners often have problems with understanding
why CDR/REST function works the way it does.

In fact, one cannot do much useful with Lisp lists prior to
understanding the connection between conses and lists.  The poster of
the original question would probably be baffled to find that

(1 . (2 . (3 . (4 . nil)))) is equal to (1 2 3 4)

-- 
Hrvoje Niksic <·······@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
* Q: What is an experienced Emacs user?
* A: A person who wishes that the terminal had pedals.
From: Mark McConnell
Subject: Re: Newbie question
Date: 
Message-ID: <33B2B29B.7680@math.okstate.edu>
Dale Bricker wrote:
> 
> Can anyone explain to me _why_ it is that if
> 
> > (first '(c d e))
> 
> returns "c", why doesn't
> 
> > (first (rest '((ab) (c d e))))
> 
> also return "c" instead of "(c d e)" ?

I wrote you a reply, but I can't get your e-mail address to work.
Mail me a correct address, and I'll send you a copy of the reply.
From: ·······@ibm.net
Subject: Re: Newbie question
Date: 
Message-ID: <867478018.26278@dejanews.com>
In article <··········@usenet.rpi.edu>,
  Dale Bricker <·······@rpi.edu> wrote:
>
> Can anyone explain to me _why_ it is that if
>
> > (first '(c d e))
>
> returns "c", why doesn't
>
> > (first (rest '((ab) (c d e))))
>
> also return "c" instead of "(c d e)" ?
>

because (rest) gives you a *list* with the rest of the
elements of a list, so (rest '((ab) (c d e))) gives
you '((c d e)).  Applying (first) gives you... right.

Job van Zuijlen

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet
From: David H Wild
Subject: Re: Newbie question
Date: 
Message-ID: <na.a1655847a2.a70220dhwild@argonet.co.uk>
People new to Lisp do have a serious problem, although it shouldn't be with
something as simple as CAR and CDR.

When you come to more complex things such as DO, DOTIMES and DOLIST nearly
every book that I have seen gives one example of each, just after the
definition. If you are working on your own, with no-one to ask, it can be
very difficult to see what changes are needed to make it do what you want,
and if you get some bits wrong you get an error message rather than just the
wrong result.

We could do with something like the Schaum's worked examples books, in
mathematics and engineering, giving lots of worked examples with full
comments.


-- 
 __  __  __  __      __ ___   _____________________________________________
|__||__)/ __/  \|\ ||_   |   /
|  ||  \\__/\__/| \||__  |  /...Internet access for all Acorn RISC machines
___________________________/ ······@argonet.co.uk
From: Kent M Pitman
Subject: Re: Newbie question
Date: 
Message-ID: <sfwg1tzs7qy.fsf@world.std.com>
In article <··························@argonet.co.uk> David H Wild
<······@argonet.co.uk> writes:

> People new to Lisp do have a serious problem, although it shouldn't
> be with something as simple as CAR and CDR. [...]  We could do with
> something like the Schaum's worked examples books, in mathematics
> and engineering, giving lots of worked examples with full comments.

The Common Lisp specification itself provides examples for quite a
large part of the language--in many cases, more than one
example--sometimes a great many.  Of course, I agree that more is
always better.  Just don't overlook this option.

What is effectively the textual equivalent of the ANSI CL spec is
available on the web as the Common Lisp HyperSpec(TM) from Harlequin.
It is also something you can download for free subject to some very
modest legal restrictions.

To browse it, see http://www.harlequin.com/books/HyperSpec/FrontMatter/
For the legal restrictions, see
 http://www.harlequin.com/books/HyperSpec/FrontMatter/About-HyperSpec.html#Legal
For download info, see  http://www.harlequin.com/books/HyperSpec/