From: Drew Adams <drew.adams@oracle.com>
To: "Robert Pluim" <rpluim@gmail.com>,
"Rudolf Adamkovič" <rudolf@adamkovic.org>
Cc: Garklein <garklein97@gmail.com>,
Thierry Volpiatto <thievol@posteo.net>,
"emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: RE: [External] : Re: Elisp threading macros
Date: Fri, 30 Aug 2024 17:15:23 +0000 [thread overview]
Message-ID: <DS7PR10MB523298BF73A3664DB7229769F3972@DS7PR10MB5232.namprd10.prod.outlook.com> (raw)
In-Reply-To: <877cbyupbb.fsf@gmail.com>
> emacs lisp already has `first', `rest' and
> `seq-do' or `dolist'. And `nth' to replace
> `caddr' etc.
Neither nth nor nthcdr replaces caddr, caar
cdadar, cdddar, etc. Each of the c[..]r
functions targets a particular part of a
list (tree) in one fell swoop.
And its name is a _picture_ of where that
part is located in the tree. Direct access,
including mentally/visually.
(Yes, it takes (a little) getting used to.)
That alone is a good reason for not only
keeping car and cdr but having them at the
back of your mind in combination, instead
of just first/rest or head/tails.
Could different chars have been used than
c, a, d, and r? Of course. The c and r
aren't needed, and we could have used f for
first and r for rest, or h for head and
t for tails, or | for car and . for cdr, or
- for car and @ for cdr:
cadaar = frff = hthh = |.|| = -@--
caar = ff = hh = || = --
caaar = fff = hhh = ||| = ---
caddar = frrf = htth = |..| = -@@-
cdadar = rfrf = thth = .|.| = @-@-
cdddar = rrrf = ttth = ...| = @@@-
caddr = frr = htt = |.. = -@@
Or Morse code: .-.. .. ... .--.
L I S P
The point is that there are 2 basic access
functions for the 2 components of a cons,
and accessing their combinations can be
abbreviated in a pictorial way with 2 chars.
___
Of course, no one would suggest that people
should _mostly_ use the more complex c[..]r
abbreviations instead of binding intermediate
vars with meaningful names to uses of smaller
access c[..]r variations (including car/cdr).
Still, when that's not so important, if a
reader is _used_ to the c[..]r pictures, an
occasional (caddar foo) can be handier than
(first (rest (rest (first foo)))) or
(first (nthcdr 1 (first foo))).
IOW, if you're going to use such first/rest
combinations anyway (instead of intermediate
vars), then the c[..]r patterns can be handy
and healthy. ;-)
It kinda depends on what one's used to.
(setq foo '((1 (2 3) 4 . 5)))
(caar foo) => 1 .. I
(caadar foo) => 2 ..-. F
(cadar foo) => (2 3) .-. R
(cadr (cadar foo)) => 3 .- (._.) A(R)
(cddar foo) => (4 . 5) --. G
(caddar foo) => 4 .--. P
(cdddar foo) => 5 ---. Ó
or O(E)
or M(N)
or T(G)
YMMV.
next prev parent reply other threads:[~2024-08-30 17:15 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-28 14:08 Elisp threading macros Garklein
2024-08-28 15:51 ` Robert Pluim
2024-08-28 16:42 ` Visuwesh
2024-08-28 17:13 ` Henrik Kjerringvåg
2024-08-28 15:55 ` Eli Zaretskii
2024-08-28 18:23 ` Basil L. Contovounesios
2024-08-31 12:50 ` Augusto Stoffel
2024-08-28 18:05 ` Philip Kaludercic
2024-08-28 19:43 ` Garklein
2024-08-28 19:54 ` Philip Kaludercic
2024-08-29 4:45 ` tomas
2024-08-30 7:30 ` Joost Kremers
2024-08-29 21:19 ` Sean Whitton
2024-08-29 21:46 ` Philip Kaludercic
2024-08-28 18:29 ` Thierry Volpiatto
2024-08-28 19:35 ` Garklein
2024-08-30 12:26 ` Rudolf Adamkovič
2024-08-30 13:12 ` Robert Pluim
2024-08-30 17:15 ` Drew Adams [this message]
2024-09-01 16:43 ` [External] : " Alfred M. Szmidt
2024-09-01 21:02 ` Drew Adams
2024-08-29 0:48 ` Po Lu
2024-08-29 5:19 ` Alfred M. Szmidt
2024-08-30 0:57 ` Garklein
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=DS7PR10MB523298BF73A3664DB7229769F3972@DS7PR10MB5232.namprd10.prod.outlook.com \
--to=drew.adams@oracle.com \
--cc=emacs-devel@gnu.org \
--cc=garklein97@gmail.com \
--cc=rpluim@gmail.com \
--cc=rudolf@adamkovic.org \
--cc=thievol@posteo.net \
/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.