all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: "Adam Sjøgren" <asjo@koldfront.dk>,
	"emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: RE: [External] : Add hints to documentation of car and cdr for (e)lisp newcomers - take 2
Date: Wed, 14 Jul 2021 16:37:53 +0000	[thread overview]
Message-ID: <SJ0PR10MB5488C7117C9A0770F8AE9682F3139@SJ0PR10MB5488.namprd10.prod.outlook.com> (raw)
In-Reply-To: <8735shrl57.fsf@tullinup.koldfront.dk>

> How about:
> 
>   ,----
>   | (car '(a . b))
>   |
>   | Return a.  If arg is nil, return nil.
>   `----
>   ,----
>   | (cdr '(a . b))
>   |
>   | Return b.  If arg is nil, return nil.
>   `----
>
> 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.
>   `----


Allow Harold Abelson to present it:

https://www.youtube.com/watch?v=DrFkf-T-6Co

See 19:12 minutes into the recording.
In particular this, at 22:44:

  For any x and y:

    (car (cons x y)) is x
    (cdr (cons x y)) is y

That's it.  Starting from knowing _nothing_
about cons, car, and cdr, that pretty much
tells you everything.  It _defines_ all 3.

(This is an algebraic specification of an
abstract data type, where "cons" is an
_unspecified_ function (function symbol),
aka a "constructor".  It defines "car" and
"cdr", and it leaves "cons" undefined.)

Except that definition leaves out the nil
case (in most Lisps, including Elisp),
which is defined by this:

    (car nil) is nil
    (cdr nil) is nil

(And except for the case where "any x or
y" is, in effect, "bottom": where trying
to evaluate their sexps produces no x or
y _value_ - raises an error or doesn't
terminate.)

You don't need to know anything else about
what cons or nil are or might be, to
understand them, car, and cdr in the
context of pairs (and lists).

Sure, to know more about using them
practically you'll want to know about `eq'
and other things.  But as for what cons,
car, and cdr _are_ (and do), that's it.

(What you said is correct, but as others
have mentioned, the notation (a . b) needs
to first be understood.)

      parent reply	other threads:[~2021-07-14 16:37 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-14 15:05 Add hints to documentation of car and cdr for (e)lisp newcomers - take 2 Adam Sjøgren
2021-07-14 15:36 ` Andreas Schwab
2021-07-14 15:48 ` tomas
2021-07-14 15:50 ` Eli Zaretskii
2021-07-14 16:03   ` Lars Ingebrigtsen
2021-07-14 16:13     ` Eli Zaretskii
2021-07-15  4:34       ` Lars Ingebrigtsen
2021-07-14 23:49     ` Stefan Kangas
2021-07-15  4:38       ` Lars Ingebrigtsen
2021-07-15 11:39         ` Stefan Kangas
2021-07-15 14:14           ` Eli Zaretskii
2021-07-15 15:02             ` Tim Cross
2021-07-15 15:41               ` Stefan Monnier
2021-07-15 15:21             ` Stefan Monnier
2021-07-15 15:26               ` Yuan Fu
2021-07-15 15:52                 ` Eduardo Ochs
2021-07-15 15:44               ` Lars Ingebrigtsen
2021-07-15 15:57                 ` Eli Zaretskii
2021-07-16  0:22                   ` Stefan Monnier
2021-07-16  2:08                     ` Jean-Christophe Helary
2021-07-16 13:22                       ` Stefan Monnier
2021-07-16 14:38                         ` Basil L. Contovounesios
2021-07-16  7:00                     ` Eli Zaretskii
2021-07-15 15:53               ` Eli Zaretskii
2021-07-15 16:17                 ` Jean-Christophe Helary
2021-07-15 16:30                   ` Lars Ingebrigtsen
2021-07-15 16:57                     ` Eli Zaretskii
2021-07-15 17:01                       ` Lars Ingebrigtsen
2021-07-15 17:07                         ` Eli Zaretskii
2021-07-15 20:54                         ` Stefan Kangas
2021-07-15 21:11                           ` Lars Ingebrigtsen
2021-07-14 16:37 ` Drew Adams [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=SJ0PR10MB5488C7117C9A0770F8AE9682F3139@SJ0PR10MB5488.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=asjo@koldfront.dk \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.