GNU bug report logs - #47327
28.0.50; (cl-generic) eql specializer not evaluated

Previous Next

Package: emacs;

Reported by: akater <nuclearspace <at> gmail.com>

Date: Mon, 22 Mar 2021 17:20:02 UTC

Severity: normal

Tags: fixed

Found in version 28.0.50

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


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

From: akater <nuclearspace <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 28.0.50; (cl-generic) eql specializer not evaluated
Date: Mon, 22 Mar 2021 17:08:09 +0000
[Message part 1 (text/plain, inline)]
In ~(eql VAL)~ specializer, ~VAL~ should evaluate during evaluation of
the macroexpanded ~cl-defmethod~ form.

For some reason =cl-generic.el= does not do that (it does not evaluate
the specializer form at all).  Here's a hack fix that seems to work for
me but I do not have a deep enough understanding of ~cl-generic~ to
actually suggest it:

#+begin_src emacs-lisp :results none
(cl-defmethod cl-generic-generalizers ((specializer (head cl:eql)))
  "Support for (eql VAL) specializers.
These match if the argument is `eql' to VAL."
  (let ((value (eval (cadr specializer) t)))
    (setf (car specializer) 'eql)
    (puthash value specializer cl--generic-eql-used))
  (list cl--generic-eql-generalizer))
#+end_src


Rationale:

(1) See Common Lisp HyperSpec:

#+begin_quote
The parameter specializer name ~(eql eql-specializer-form)~
indicates that the corresponding argument must be eql to the object
that is the value of ~eql-specializer-form~ for the method to be applicable.
The ~eql-specializer-form~ is evaluated
at the time that the expansion of the defmethod macro is evaluated.
#+end_quote
---
[[http://www.lispworks.com/documentation/HyperSpec/Body/m_defmet.htm][Macro
DEFMETHOD]]


(2) With eql specializer form not evaluated it does not seem possible to
e.g. use a custom method combination, even though ~cl-generic~ informs
that it is possible.  The only way I can think of, is
specializing ~cl-generic-combine-methods~ on the particular generic
function:

#+begin_src emacs-lisp :results none :eval never
(cl-defmethod cl-generic-combine-methods ((generic
                                           (cl:eql
                                            (cl--generic
                                             'my-generic-function)))
                                          methods)
  "Use `my-method-combination' method for generic function `my-generic-function'."
  (my-method-combination generic methods))
#+end_src

which is impossible if the specializer form is not evaluated.


(3) With eql specializer form not evaluated, it is only possible to
dispatch on eql numbers or eql symbols which is needlessly limited.
[signature.asc (application/pgp-signature, inline)]

This bug report was last modified 3 years and 277 days ago.

Previous Next


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