[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: combining cond and let, to replace pcase.
From: |
Richard Stallman |
Subject: |
Re: combining cond and let, to replace pcase. |
Date: |
Tue, 28 Nov 2023 22:41:41 -0500 |
[[[ To any NSA and FBI agents reading my email: please consider ]]]
[[[ whether defending the US Constitution against all enemies, ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]
> (pcase 42
> (`(,x . ,y) (format "%s:%s" x y))
> (_ "not a cons cell"))
> → not a cons cell
> If I understand Richard correctly,
Alas I think we are miscommunicating.
the corresponding :match will
> unconditionally attempt to bind x to (car 42) and y to (cdr 42), which
> results in a run-time error.
pcase has one kind of matching clause.
cond* has two kinds.
It is possible that this distinction is not clear enough in the text I
posted.
In this version, each clause exits if it contains more than one
element (after the possible keyword), and falls through
unconditionally if it has only one element (after the possible
keyword).
For the second kind, I think this addresses your concern.
(cond*
;; Same as a clause in `cond',
(CONDITION
DO-THIS-IF-TRUE-THEN-EXIT...)
;; Execute FORM and ignore its value.
(FORM)
;; Variables to bind, as in let
(:bind ((x foobar) y z (foo 5) a))
;; Bindings continue in effect.
;; Extracts substructure and binds variables around the rest
;; of the cond*.
(:match (`(expt ,foo ,bar) x)
DO-THIS-IF-IT-MATCHED-THEN-EXIT...)
;; Bindings no longer in effect.
;; Like above but always falls thru to next clause.
(:match (`(expt ,foo ,bar) x))
;; Bindings continue in effect.
;; All the variables mentioned in the pattern
;; are bound whether match succeeds or not.
;; If a value can be determined from an incomplete match,
;; the variable gets that value.
)
--
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)
- Re: combining cond and let, to replace pcase., (continued)
- Re: combining cond and let, to replace pcase., Richard Stallman, 2023/11/25
- Re: combining cond and let, to replace pcase., Daniel Semyonov, 2023/11/23
- Re: combining cond and let, to replace pcase., Daniel Semyonov, 2023/11/23
- Re: combining cond and let, to replace pcase., Richard Stallman, 2023/11/24
- Re: combining cond and let, to replace pcase., Stefan Monnier, 2023/11/25
- Re: combining cond and let, to replace pcase., Richard Stallman, 2023/11/26
- Re: combining cond and let, to replace pcase., Richard Stallman, 2023/11/26
- Re: combining cond and let, to replace pcase., Manuel Giraud, 2023/11/27
- Re: combining cond and let, to replace pcase., Yuri Khan, 2023/11/27
- Re: combining cond and let, to replace pcase., Stefan Monnier, 2023/11/27
- Re: combining cond and let, to replace pcase.,
Richard Stallman <=
- Re: combining cond and let, to replace pcase., Richard Stallman, 2023/11/28
Re: Instead of pcase, Jim Porter, 2023/11/16
- Re: Instead of pcase, Po Lu, 2023/11/17
- Re: Instead of pcase, Michael Heerdegen, 2023/11/19
- Re: Instead of pcase, Eli Zaretskii, 2023/11/19
- Re: Instead of pcase, Dmitry Gutov, 2023/11/19
- Re: Instead of pcase, Po Lu, 2023/11/19
- Re: Instead of pcase, Dmitry Gutov, 2023/11/19
- Re: Instead of pcase, Eli Zaretskii, 2023/11/19
- Re: Instead of pcase, Dmitry Gutov, 2023/11/19