emacs-devel
[Top][All Lists]
Advanced

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




reply via email to

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