emacs-devel
[Top][All Lists]
Advanced

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





reply via email to

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