emacs-devel
[Top][All Lists]
Advanced

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

Re: Instead of pcase


From: Tomas Hlavaty
Subject: Re: Instead of pcase
Date: Thu, 16 Nov 2023 21:16:01 +0100

On Thu 16 Nov 2023 at 10:20, Spencer Baugh <sbaugh@janestreet.com> wrote:
> (let ((exp (if t '(foo . "str") '(bar . 7))))
>   (pcase exp
>     (`(foo . ,val) (concat "str" val))
>     (`(bar . ,val) (+ 1 val))))

(`(foo . ,val) (concat "str" val)) looks very strange.
One does not write (let ((,val ...)) ...).

Maybe (('foo . val) (concat "str" val)) would make more sense?

> and with cond-let one could write:
>
> (let ((exp (if t '(foo . "str") '(bar . 7))))
>   (cond-let
>    ((val
>      (and (eq (car exp) 'foo) (cdr exp)))
>     (concat "str" val))
>    ((val
>      (and (eq (car exp) 'bar) (cdr exp)))
>     (+ 1 val))))
>
> Which is maybe nicer?

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

It is a shame that case, ecase, typecase and etypecase are (were moved?)
to cl-lib.



reply via email to

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