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


View this message in rfc822 format

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: bug#77725: 31.0.50; Add support for types accepted by `cl-typep' to cl-generic?
Date: Thu, 8 May 2025 13:55:13 +0200
Just to let you know that I now switched my own libraries to use the
builtin derived types, and they work nicely :-)

I am following your last (great) changes on master, and I wonder if
the method `cl-generic-generalizers' in cl-lib:

  (cl-defmethod cl-generic-generalizers :extra "derived-types" (type)
    "Support for dispatch on derived types, i.e. defined with `cl-deftype'."
    (if (and (symbolp type) (cl-derived-type-class-p (cl--find-class type))
             ;; Make sure this derived type can be used without arguments.
             (let ((expander (get type 'cl-deftype-handler)))
               (and expander (with-demoted-errors "%S" (funcall expander)))))
        (cl--derived-type-generalizers type)
      (cl-call-next-method)))

Could now be simplified like this:

  (cl-defmethod cl-generic-generalizers :extra "derived-types" (type)
    "Support for dispatch on derived types, i.e. defined with `cl-deftype'."
    (if (and (symbolp type) (cl-derived-type-class-p (cl--find-class type))
             ;; Make sure this derived type can be used without arguments.
             (memq type cl--derived-type-list)) ;; <<<<<<<<<<<<<<<<<<<
        (cl--derived-type-generalizers type)
      (cl-call-next-method)))

Because `cl--define-derived-type' ensures that only type without
arguments are in `cl--derived-type-list'.  This will also ensure
that the type had no error (otherwise it would have been removed
from `cl--derived-type-list'), for free ;-)

Thanks!
David




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.