emacs-compat / compat

COMPATibility Library for Emacs Lisp
https://elpa.gnu.org/packages/compat.html
GNU General Public License v3.0
69 stars 12 forks source link

New pcase patterns such as cl-typep #55

Open tarsius opened 1 month ago

tarsius commented 1 month ago

Please consider backporting newer pcase patterns such as cl-typep and eieio. Beside these two, there are probably some additional patterns that weren't available in the very first pcase. Such patterns are defined using pcase-defmacro, and take very little code.

Thanks for considering!

minad commented 1 month ago

Hi @tarsius,

I consider pcase extensions out of scope of Compat. The pcase library is simply too complex and too difficult to extend, since we have to work with the earliest versions. I've tried porting back pcase-related functionality before and I failed. Iirc we've talked about this before? Nevertheless I am happy to be proven wrong if it is indeed possible to port back certain subsets of the functionality.

tarsius commented 1 month ago

I'm currently backporting the cl-typep pattern in transient.el like so:

(eval-and-compile ; Needed because we use this pattern below.
  (when (< emacs-major-version 28)
    (pcase-defmacro cl-type (type)
      "Pcase pattern that matches objects of TYPE.
TYPE is a type descriptor as accepted by `cl-typep', which see."
      (static-if (< emacs-major-version 30)
          `(pred (pcase--flip cl-typep ',type))
        ;; This isn't actually ever used but we have to hide
        ;; the above from the byte-compiler for upcoming releases,
        ;; and might as well include this here to show what the
        ;; built-in version looks like in those upcoming releases.
        `(pred (cl-typep _ ',type))))))

Seems simple enough.

tarsius commented 1 month ago

Iirc we've talked about this before?

We talked about pcase-setq.