[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: cond* vs pcase
From: |
Alfred M. Szmidt |
Subject: |
Re: cond* vs pcase |
Date: |
Tue, 06 Feb 2024 11:17:05 -0500 |
"Alfred M. Szmidt" <ams@gnu.org> writes:
> I use pcase often; but I use it just as a better cond. For example I
find this
> handy:
>
> (defvar foo nil) <-- foo is some symbol
>
> (pcase foo
> ('bar (do-some-bar-stuff))
> ('baz (do-some-baz-fluff)))
>
> cl-case seems more appropriate here (wish cl-case was just case ...)
Why more appropriate?
Because your not doing pattern matching, you're comparing against a
set of strings/symbols/numbers/....
I always think of pcase as Elisp's case. In
addition, pcase avoids the danger of naively writing
(cl-case foo
('bar (do-some-bar-stuff))
('baz (do-some-baz-fluff)))
and then getting surprised when foo evaluates to `quote'.
Suprises will happy, you will get suprises with pcase and cond* too --
I find it suprising that to match over symbols requires pattern
matching. One might also question why you (well, no you specifically)
are comparing against (quote bar) etc? That is a suprise in it self...
> or this:
>
> (setq foo "some-string")
>
> (pcase foo
> ("foo" (do-foo-case))
> ("bar" (do-bar-case)))
>
> Same here, with (intern foo) ...
Being able to do equal instead of eql is also something that speaks in
favour of pcase...
It speaks more in favor of having CASE where you can change the
comparison operator or a CASE-STRING or similar, not something much
more generic pcase (or even cond*!) -- i.e. why use pcase/cond* when
you're not using any of the features that are the main point of those
two macros.
- cond* vs pcase, Arthur Miller, 2024/02/05
- Re: cond* vs pcase, Eli Zaretskii, 2024/02/05
- Re: cond* vs pcase, Alfred M. Szmidt, 2024/02/05
- Re: cond* vs pcase, Philip Kaludercic, 2024/02/05
- Re: cond* vs pcase, Arthur Miller, 2024/02/06
- Re: cond* vs pcase,
Alfred M. Szmidt <=
- RE: [External] : Re: cond* vs pcase, Drew Adams, 2024/02/06
- Re: cond* vs pcase, Philip Kaludercic, 2024/02/06
- Re: cond* vs pcase, Alfred M. Szmidt, 2024/02/06
- Re: cond* vs pcase, Philip Kaludercic, 2024/02/06
- Re: cond* vs pcase, Alfred M. Szmidt, 2024/02/06
- Re: cond* vs pcase, Philip Kaludercic, 2024/02/06
- RE: [External] : Re: cond* vs pcase, Drew Adams, 2024/02/06
- RE: [External] : Re: cond* vs pcase, Drew Adams, 2024/02/06
- RE: [External] : Re: cond* vs pcase, Adam Porter, 2024/02/06
- RE: [External] : Re: cond* vs pcase, Drew Adams, 2024/02/06