GNU bug report logs - #77725
31.0.50; Add support for types accepted by `cl-typep' to cl-generic?

Previous Next

Package: emacs;

Reported by: David Ponce <da_vid <at> orange.fr>

Date: Fri, 11 Apr 2025 07:16:01 UTC

Severity: normal

Found in version 31.0.50

Full log


Message #32 received at 77725 <at> debbugs.gnu.org (full text, mbox):

From: David Ponce <da_vid <at> orange.fr>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 77725 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#77725: 31.0.50; Add support for types accepted by `cl-typep'
 to cl-generic?
Date: Mon, 14 Apr 2025 16:24:04 +0200
[Message part 1 (text/plain, inline)]
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)




[gtype.el (text/x-emacs-lisp, attachment)]

This bug report was last modified 10 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.