[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Advantage using mapc over dolist
From: |
Heime |
Subject: |
Re: Advantage using mapc over dolist |
Date: |
Tue, 03 Dec 2024 19:35:20 +0000 |
Sent with Proton Mail secure email.
On Wednesday, December 4th, 2024 at 7:27 AM, Tomas Hlavaty <tom@logand.com>
wrote:
> 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
You want to do same job, finding a specific command that has the capability
for doing nothing else than what you need is wasting your time. But there
are many who like to delve on the technicalities about what they use, and
are not much interested is just getting the job done.
> pushing for general omnipotent
> use-me-i-can-do-everything-youll-ever-need macro is a bad idea
Total nonsense. If a function can do what you need, use it.
- Re: Advantage using mapc over dolist, (continued)
Re: Advantage using mapc over dolist, Stefan Monnier, 2024/12/03
- Re: Advantage using mapc over dolist, Tomas Hlavaty, 2024/12/03
- Re: Advantage using mapc over dolist, Stefan Monnier, 2024/12/03
- Re: Advantage using mapc over dolist, Alfred M. Szmidt, 2024/12/03
- Re: Advantage using mapc over dolist, Stefan Monnier, 2024/12/03
- Re: Advantage using mapc over dolist, Tomas Hlavaty, 2024/12/03
- Re: Advantage using mapc over dolist,
Heime <=
Re: Advantage using mapc over dolist, Tomas Hlavaty, 2024/12/03
Re: Advantage using mapc over dolist, Tomas Hlavaty, 2024/12/03
Re: Advantage using mapc over dolist, Tomas Hlavaty, 2024/12/03
Re: Advantage using mapc over dolist, Eli Zaretskii, 2024/12/03
Re: Advantage using mapc over dolist, Tomas Hlavaty, 2024/12/03
Re: Advantage using mapc over dolist, Eli Zaretskii, 2024/12/03
Re: Advantage using mapc over dolist, Tomas Hlavaty, 2024/12/03
Re: Advantage using mapc over dolist, Heime, 2024/12/03
Re: Advantage using mapc over dolist, Alfred M. Szmidt, 2024/12/03
Re: Advantage using mapc over dolist, Heime, 2024/12/03