Subject: Re: bug#77725: 31.0.50; Add support for types accepted by `cl-typep' to cl-generic?

From: David Ponce <[email-masked]>
Date: Mon, 14 Apr 2025 16:24:04 +0200

On 2025-04-13 19:10, Stefan Monnier wrote:
> 
> In case it can help, here's some example:
> 
>      (cl-defmethod my-foo ((x symbol))
>        (message "%S is a symbol" x))
> 
> If I call `(my-foo nil)` it will report that nil is a symbol, even
> though `(cl-type-of nil)` returns `null` rather than `symbol`.
> 
> If I add a new method for `null`:
> 
>      (cl-defmethod my-foo ((x null))
>        (message "%S is null" x)
>        (cl-call-next-method))
> 
> Now a call to `(my-foo nil)` will report both that nil is null and that
> it's a symbol (in that order).
> 
> For your `button` example, we'd similarly want that
> 
>      (cl-defmethod my-foo ((x icon))
>        (message "%S is an icon" x)
>        (cl-call-next-method))
> 
> `(my-foo 'button)` reports button as both an icon and a symbol (in that
> order).  Now let's say we add:
> 
>      (defgtype face nil ()
>        "Builtin face type."
>        '(and symbol (satisfies facep)))
> 
>      (cl-defmethod my-foo ((x face))
>        (message "%S is an face" x)
>        (cl-call-next-method))
> 
> We'd want `(my-foo 'button)` now to report that button is an icon,
> a face, and a symbol (and here I think it's OK if the ordering between
> icon and face is arbitrary, tho they should both come before symbol).
> 
> One way you could do that is for your `(gtype-of 'button)` to return
> some new `face&icon` type and to have your SPECIALIZERS-FUNCTION return
> the list `(face icon symbol)` or `(icon face symbol)` for that type.
> 
> Does that help?

Thank you very much Stefan, it helped much!
J'aperçois enfin la lumière au bout du tunnel :-)

I understand more how cl-generic works, and I reworked gtype.el
(attached) according to your inputs and my better understanding.

Now your examples above give the expected results :-)

And:

(gtype-of '(foo . foo))
=> (cons-car-foo cons-cdr-foo cons)

(gtype--specializers (gtype-of '(foo . foo)))
=> (cons-car-foo cons-cdr-foo cons list sequence t)