emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Instead of pcase


From: Stefan Monnier
Subject: Re: Instead of pcase
Date: Fri, 24 Nov 2023 23:34:24 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

> (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 :-)


        Stefan




reply via email to

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