emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Add hints to documentation of car and cdr for (e)lisp newcomers - ta


From: tomas
Subject: Re: Add hints to documentation of car and cdr for (e)lisp newcomers - take 2
Date: Wed, 14 Jul 2021 17:48:47 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Wed, Jul 14, 2021 at 05:05:24PM +0200, Adam Sjøgren wrote:
> Ten years ago I was confused by the documentation of car and cdr:
> 
>   ,----
>   | (car LIST)
>   | 
>   | Return the car of LIST.  If arg is nil, return nil.
>   `----
> 
>   ,----
>   | (cdr LIST)
>   | 
>   | Return the cdr of LIST.  If arg is nil, return nil.
>   `----

Yes, this is quite a bit of LISP lore, which is based on how lists
are built of pairs. You have to keep those two concepts apart...

> Or what about:
> 
>   ,----
>   | (car LIST)
>   | 
>   | Return the car of LIST, eg if LIST is '(a . b) return a.  If arg is nil, 
> return nil.
>   `----
> 
>   ,----
>   | (cdr LIST)
>   | 
>   | Return the cdr of LIST, eg if LIST is '(a . b) return b.  If arg is nil, 
> return nil.
>   `----

... this, for example, doesn't exactly work: '(a . b) is not a (proper) list 
(unless
b is a list itself).

I think there's no way around drawing some box-and-pointer diagrams yourself.

If you are focusing on lists, perhaps the best way to view this is
that the car is the first element of the list and the cdr is the
rest of the list:

  (car '(a b c d e)) => 'a
  (cdr '(a b c d e)) => '(b c d e)

Now I don't know where your issue is. Is it the mnemonics for `car' and `cdr'?
Or the lack of a more thorough introduction on how lists are built of pairs?

Cheers
 - t

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]