[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [External] : Re: Instead of pcase
From: |
Drew Adams |
Subject: |
RE: [External] : Re: Instead of pcase |
Date: |
Tue, 12 Dec 2023 21:36:48 +0000 |
> in plain lisp with much clearer control-flow (not tested):
>
> (defun byte-optimize-letX (form)
> (if (consp form)
> (let ((head (car form))
> (bindings (cadr form))
> (body (cddr form)))
> (if bindings
> (let ((const (car body))
> (rest (cdr body)))
> (if (or (not body)
> (and (macroexp-const-p const)
> (not rest)))
> ;; Body is empty or a constant.
> (if (eq head 'let)
> `(progn
> ,@(mapcar #'cadr bindings)
> ,const)
> `(,head
> ,(butlast bindings)
> ,(cadar (last bindings)) ,const))
> (if (let ((last-var (car-safe (car (last bindings)))))
> (and (symbolp last-var)
> (equal body (list last-var))))
> ;; Body does nothing but return the last variable in
> bindings.
> (if (eq head 'let)
> `(progn
> ,@(mapcar #'cadr bindings))
> `(,head
> ,(butlast bindings)
> ,(cadar (last bindings))))
> form))
> ;; Bindings list is empty.
> `(progn ,@body)))
> form)))
<nit>
Maybe a little clearer than (if (consp xxx)
(huge tree sexp)
xxx)
is (if (atom xxx)
xxx
(huge tree sexp))
I think more than a few folks forget about `atom', for
some reason. (Sometimes I see (not (consp xxx)) or
even (!) (null (consp xxx)).)
</nit>
- Re: Instead of pcase, (continued)
- Re: Instead of pcase, Richard Stallman, 2023/12/11
- Re: Instead of pcase, Tomas Hlavaty, 2023/12/12
- RE: [External] : Re: Instead of pcase, Drew Adams, 2023/12/12
- Re: [External] : Re: Instead of pcase, Richard Stallman, 2023/12/13
- RE: [External] : Re: Instead of pcase, Drew Adams, 2023/12/14
- Re: [External] : Re: Instead of pcase, Richard Stallman, 2023/12/15
- RE: [External] : Re: Instead of pcase, Drew Adams, 2023/12/16
- RE: [External] : Re: Instead of pcase, Bob Rogers, 2023/12/16
- Re: [External] : Re: Instead of pcase, Richard Stallman, 2023/12/17
- Re: Instead of pcase, Tomas Hlavaty, 2023/12/12
- RE: [External] : Re: Instead of pcase,
Drew Adams <=
- Re: [External] : Re: Instead of pcase, Michael Heerdegen, 2023/12/12
- 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, 2023/12/20
- Re: cond*, João Távora, 2023/12/21
- RE: [External] : Re: cond*, Drew Adams, 2023/12/21