emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Some improvements for cl-flet


From: Stefan Monnier
Subject: Re: Some improvements for cl-flet
Date: Sun, 12 Sep 2021 22:26:31 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> (cl-flet ((multilinep (apply-partially #'string-match-p "\n")))
>   (pcase something
>     ((and (pred stringp) (pred multilinep)) ...)
>     ...))

FWIW, this is better written as

    (cl-flet ((multilinep (s) (string-match-p "\n" s)))
      ...)

which is both shorter and more efficient.  But there are other cases
where the "simple" form of `cl-flet` is more efficient and the CL
version would need to be of the form

    (flet ((FOO (&rest args) (apply BAR args)))
      ...)

or worse

    (let ((bar (BAR BAZ))
      (flet ((FOO (&rest args) (apply bar args)))
        ...)

which would introduce a significant inefficiency and which can be
difficult for the compiler to optimize back to the efficiency of the
code that our `cl-flet` gets without any effort.

Its true that our `cl-flet` introduces an incompatibility with CL's
semantics, but I considered that it's sufficiently minor that the
tradeoff is worth it (as compared to introducing a separate new form).


        Stefan




reply via email to

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