[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: cond*
From: |
Richard Stallman |
Subject: |
Re: cond* |
Date: |
Wed, 20 Dec 2023 23:20:36 -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. ]]]
> am I going to use BAR and FOO
Are you talking about this?
(cond*
((match* `(expt ,foo ,bar) x))
(t
(something-that-depends-on FOO BAR) ; is this how to use it?
)
in a form that is not contained
> in any form that declares BAR and FOO as they are matched
> and bound?
"Declares BAR and FOO as they are matched and bound"
is somewhat stramge usage of those words. It is not
entirely clear what that means. And I am not sure
what code you are talking about.
What you quoted is not an example of code. It presents various sorts
of clauses that a cond* can contain, but not meant as one cond*
expression. Those clauses do not try to work together validly. So
you're judging them by a criterion they do not try to fit.
This tries to be a real example:
(defun byte-optimize-letX (form)
(cond*
;; Bindings list is empty.
((match* `(,_ () . ,body) form)
`(progn . ,body))
;; Decompose the form
((match* `(,head ,bindings . ,body) form))
;; Body is empty or just contains a constant.
((match* (or `() `(,(macroexp-const-p const))) body)
;; If the match succeeds, it always binds CONST.
(if (eq head 'let)
`(progn ,@(mapcar #'cadr bindings) ,const)
`(,head ,(butlast bindings) ,(cadar (last bindings)) ,const)))
;; Body does nothing but return the last variable in bindings.
((let ((last-var (car-safe (car (last bindings)))))
;; Next line could be written using `match',
;; but the clarity of this is worth one cons.
(and (symbolp last-var) (equal body (list last-var))))
(if (eq head 'let)
`(progn ,@(mapcar #'cadr bindings))
`(,head ,(butlast bindings) ,(cadar (last bindings)))))
(t form)))
head, bindings and body are bound in the cond* form, as specified
by the fall-through second clause, and they can be used
in the rest of the cond* clause.
--
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: [External] : Re: Instead of pcase, (continued)
- Re: Instead of pcase, Adam Porter, 2023/12/12
- Re: Instead of pcase, Richard Stallman, 2023/12/13
- Re: Instead of pcase, Richard Stallman, 2023/12/15
- Re: Instead of pcase, Richard Stallman, 2023/12/15
- cond*, Richard Stallman, 2023/12/17
- Re: cond*, João Távora, 2023/12/18
- Re: cond*,
Richard Stallman <=
- Re: cond*, João Távora, 2023/12/21
- RE: [External] : Re: cond*, Drew Adams, 2023/12/21
- Re: [External] : Re: cond*, João Távora, 2023/12/21
- Re: [External] : Re: cond*, Richard Stallman, 2023/12/23
- Re: cond*, Richard Stallman, 2023/12/23
- Re: cond*, Ihor Radchenko, 2023/12/21
- Re: cond*, Richard Stallman, 2023/12/23
- Re: cond*, Ihor Radchenko, 2023/12/25
- Re: cond*, Richard Stallman, 2023/12/18
- Re: cond*, João Távora, 2023/12/19