emacs-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] pcase.el: Add type pattern


From: Stefan Monnier
Subject: Re: [PATCH] pcase.el: Add type pattern
Date: Mon, 09 Mar 2020 14:53:11 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> It seemed like an obvious and useful improvement to add a "type" pattern
> to pcase, so I prepared this patch.

A `type` pattern seems fine, yes.

> I wondered if checking for predicates like this was a good way to do so,

`cl-typep` does it but I think it's a mistake.
We should not rely on such heuristics when we can "do it right",
e.g. with a property along the lines of `cl-deftype-satisfies`.

> +      (pred (or (intern-soft (concat type "p"))
> +                (intern-soft (concat type "-p"))

This fails for those cl-defstructs where the `:predicate` was given another
name (or no name at all).

We could circumvent the problem by expanding the (type T) check to
to a call to `cl-typep`.


        Stefan


PS: Arguably, every type symbol should have a corresponding *class*
(currently stored in the `cl--class` symbol for cl-defstruct and eieio
objects), so we should then add a bunch of classes for non-structs
non-eieio types (such as integer, ...) and we could then define
a generic function which takes such a class and returns the predicate to
use as a test for this type.




reply via email to

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