emacs-devel
[Top][All Lists]
Advanced

[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'.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]