[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Instead of pcase
From: |
Eli Zaretskii |
Subject: |
Re: Instead of pcase |
Date: |
Sat, 25 Nov 2023 10:53:34 +0200 |
> Date: Fri, 24 Nov 2023 23:34:24 -0500
> From: Stefan Monnier via "Emacs development discussions."
> <emacs-devel@gnu.org>
>
> > (let ((exp (if t '(foo . "str") '(bar . 7))))
> > (cl-case (car exp)
> > (foo
> > (when-let ((d (cdr exp)))
> > (concat "str" val)))
> > (bar
> > (when-let ((d (cdr exp)))
> > (1+ val)))))
>
> AKA
>
> (let ((exp (if t '(foo . "str") '(bar . 7))))
> (case (car exp)
> ('foo
> (when-let ((d (cdr exp)))
> (concat "str" val)))
> ('bar
> (when-let ((d (cdr exp)))
> (1+ val)))))
>
> Funnily enough this quoting of the values against which we want to match
> is so natural for coders not familiar with `cl-case` that we went
> through some efforts to try and detect their mis-use.
>
> So at least for some coders, in the above case, the `pcase` syntax is the
> more natural one :-)
And 'cond' is more natural yet (in these simple cases). Basically,
all that pcase saves us there is the call to 'eq'.
- Re: Instead of pcase, (continued)
- Re: Instead of pcase, Spencer Baugh, 2023/11/16
- Re: Instead of pcase, Tomas Hlavaty, 2023/11/16
- combining cond and let, to replace pcase., Richard Stallman, 2023/11/17
- Re: combining cond and let, to replace pcase., Michael Heerdegen, 2023/11/19
- Re: combining cond and let, to replace pcase., Eli Zaretskii, 2023/11/19
- Re: combining cond and let, to replace pcase., Gerd Möllmann, 2023/11/19
- Re: combining cond and let, to replace pcase., Eli Zaretskii, 2023/11/19
- Re: combining cond and let, to replace pcase., Gerd Möllmann, 2023/11/19
- Re: combining cond and let, to replace pcase., Eli Zaretskii, 2023/11/19
- Re: combining cond and let, to replace pcase., Gerd Möllmann, 2023/11/19
- Re: combining cond and let, to replace pcase., Eli Zaretskii, 2023/11/19
- Re: combining cond and let, to replace pcase., Joost Kremers, 2023/11/19