[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Instead of pcase
From: |
Spencer Baugh |
Subject: |
Re: Instead of pcase |
Date: |
Thu, 16 Nov 2023 10:20:49 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Setting aside whether pcase is good or not:
I've thought before that it would be nice to have a cond-let construct,
like if-let and when-let. The body of a cond clause would be bound to
the result of the condition. Perhaps that could be a good alternative
to some use-cases for pcase?
For example, if one has a cons whose cdr is a string if the car is 'foo,
and whose cdr is a number if the car is 'bar, then with pcase one can
write:
(let ((exp (if t '(foo . "str") '(bar . 7))))
(pcase exp
(`(foo . ,val) (concat "str" val))
(`(bar . ,val) (+ 1 val))))
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?
- Re: Instead of pcase, (continued)
Re: Instead of pcase, Michael Heerdegen, 2023/11/16
Re: Instead of pcase, Richard Stallman, 2023/11/19
Re: Instead of pcase,
Spencer Baugh <=
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