[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.
Re: Instead of pcase, Spencer Baugh, 2023/11/16
- Re: Instead of pcase,
Tomas Hlavaty <=
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