From: Tomas Hlavaty <tom@logand.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>,
"Alfred M. Szmidt" <ams@gnu.org>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Advantage using mapc over dolist
Date: Tue, 03 Dec 2024 20:27:24 +0100 [thread overview]
Message-ID: <87v7w04ler.fsf@neko.mail-host-address-is-not-set> (raw)
In-Reply-To: <jwvr06o65zm.fsf-monnier+emacs@gnu.org>
On Tue 03 Dec 2024 at 12:24, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> > on the contrary, it is better to use specific tools and avoid more
>> > general tools when possible in order to lower cognitive load.
>> Again, that's a personal preference. If you have to learn the more
>> general tool anyway, then having to additionally learn the more specific
>> tool may increase rather than lower the cognitive load.
>> Then why not use COND*?
>
> AFAICT, the "cognitive load" of a complex pattern language is about the
> same for `pcase` as for `match*` since the two pattern languages are
> very similar.
>
> And in the case of code that can use `case/ecase`, `cond*` doesn't seem
> to provide much benefit over just `cond` or `pcase`. Compare:
not only syntax but also semantics is important
not only things that are possible are important
but also things that are not possible
very limited stuff can happen using case/ecase
this is not the case with pcase so one has to keep in mind many more
possibilities
compare IF and WHEN. IF is more general and using your logic, one
should use IF and forget WHEN. however, the reduction of cognitive load
comes also from _things that cannot happen_, e.g. there is no "else"
branch to watch out for when using WHEN. Thus writing (if x 42) is
worse than writing (when x 42). It conveys the intention much better.
And is more robust.
> (pcase actm
> ('armg (do-this))
> ('go (do-that))))
(let ((x 'go))
(pcase x
('armg 1)
('go 2)))
=> 2
(let ((x 'go))
(pcase x
(armg 1)
(go 2)))
=> 1
here the PATTERN leads to many more possibilities
> (case actm
> (armg (do-this))
> (go (do-that))))
(let ((x 'go))
(cl-case x
('armg 1)
('go 2)))
=> 2
(let ((x 'go))
(cl-case x
(armg 1)
(go 2)))
=> 2
here the KEYLIST leads to much less possibilities
> (cond
> ((eq actm 'armg (do-this)))
> ((eq actm 'go (do-that))))
>
> vs
>
> (cond*
> ((eq actm 'armg) (do-this))
> ((eq actm 'go) (do-that)))
>
> or
>
> (cond*
> ((match* `armg actm) (do-this)))
> ((match* `go actm) (do-that))))
obviously these examples are significantly worse than CASE
you meant:
(cond
((eq actm 'armg) (do-this))
((eq actm 'go) (do-that)))
and cond is simpler and more specific than cond*
so again, use simpler, more specific tool for the job and the code will
be more readable and maintainable
pushing for general omnipotent
use-me-i-can-do-everything-youll-ever-need macro is a bad idea
next prev parent reply other threads:[~2024-12-03 19:27 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-01 23:31 Advantage using mapc over dolist Heime via Users list for the GNU Emacs text editor
2024-12-02 6:26 ` Tomas Hlavaty
2024-12-02 18:30 ` Heime via Users list for the GNU Emacs text editor
2024-12-02 20:41 ` Tomas Hlavaty
2024-12-02 20:50 ` Jean Louis
2024-12-02 21:21 ` Tomas Hlavaty
2024-12-02 21:41 ` Heime via Users list for the GNU Emacs text editor
2024-12-03 6:13 ` Jean Louis
2024-12-03 7:36 ` Tomas Hlavaty
2024-12-03 19:24 ` Jean Louis
2024-12-03 20:04 ` Tomas Hlavaty
2024-12-03 20:09 ` Jean Louis
2024-12-03 20:12 ` Heime via Users list for the GNU Emacs text editor
2024-12-03 20:24 ` Jean Louis
2024-12-02 20:56 ` Heime via Users list for the GNU Emacs text editor
2024-12-03 19:26 ` Jean Louis
2024-12-03 19:39 ` Heime via Users list for the GNU Emacs text editor
2024-12-03 14:11 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-12-03 14:48 ` Tomas Hlavaty
2024-12-03 16:31 ` Stefan Monnier
2024-12-03 17:00 ` Alfred M. Szmidt
2024-12-03 17:24 ` Stefan Monnier
2024-12-03 19:27 ` Tomas Hlavaty [this message]
2024-12-03 19:35 ` Heime via Users list for the GNU Emacs text editor
2024-12-03 14:59 ` Tomas Hlavaty
2024-12-03 15:40 ` Tomas Hlavaty
2024-12-03 15:57 ` Tomas Hlavaty
2024-12-03 17:11 ` Eli Zaretskii
2024-12-03 17:33 ` Tomas Hlavaty
2024-12-03 17:40 ` Eli Zaretskii
2024-12-03 17:55 ` Tomas Hlavaty
2024-12-03 18:05 ` Heime via Users list for the GNU Emacs text editor
2024-12-03 18:57 ` Alfred M. Szmidt
2024-12-03 19:06 ` Heime via Users list for the GNU Emacs text editor
2024-12-03 20:15 ` Tomas Hlavaty
2024-12-04 5:37 ` Alfred M. Szmidt
2024-12-03 19:42 ` Jean Louis
2024-12-03 19:54 ` Heime via Users list for the GNU Emacs text editor
2024-12-03 20:11 ` Jean Louis
2024-12-03 16:47 ` Stefan Monnier
2024-12-03 18:01 ` Heime via Users list for the GNU Emacs text editor
2024-12-03 20:05 ` Jean Louis
2024-12-03 20:35 ` Tomas Hlavaty
2024-12-03 23:29 ` Stefan Monnier
2024-12-04 0:57 ` Heime via Users list for the GNU Emacs text editor
2024-12-04 2:20 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-12-03 19:38 ` Jean Louis
2024-12-04 4:56 ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-12-02 6:59 ` Tassilo Horn
2024-12-02 10:12 ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-12-02 17:03 ` Heime via Users list for the GNU Emacs text editor
2024-12-02 18:51 ` Tomas Hlavaty
2024-12-02 20:17 ` Heime via Users list for the GNU Emacs text editor
2024-12-02 21:07 ` Tomas Hlavaty
2024-12-03 13:19 ` Tomas Hlavaty
2024-12-02 21:15 ` [External] : " Drew Adams
2024-12-02 21:58 ` Tomas Hlavaty
2024-12-02 22:42 ` Drew Adams
2024-12-03 5:49 ` Tomas Hlavaty
2024-12-03 20:08 ` Lazy functional programming [was: Advantage using mapc over dolist] Drew Adams
2024-12-03 21:17 ` Tomas Hlavaty
2024-12-04 4:33 ` Advantage using mapc over dolist Michael Heerdegen
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=87v7w04ler.fsf@neko.mail-host-address-is-not-set \
--to=tom@logand.com \
--cc=ams@gnu.org \
--cc=help-gnu-emacs@gnu.org \
--cc=monnier@iro.umontreal.ca \
/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.