Discussion:
One annoyance of ensure-generic-function-using-class
Didier Verna
2017-12-27 11:50:48 UTC
Permalink
Hello,

there is something annoying with
ensure-generic-function-using-class. The MOP specifies that if the
:generic-function-class option is not provided, it defaults to
standard-generic-function. While this makes perfect sense when the
generic function doesn't already exist, it seems to also apply when it
does.

As a result, if you want to call ensure-generic-function on an existing
generic function using a different meta-class, for instance like this:

(ensure-generic-function gf-name :generic-function-class (class-of gf))


This is a bit annoying, and I don't understand the rationale behind
this, if there's one. Why not defaulting to the existing generic
function's meta-class?
--
Resistance is futile. You will be jazzimilated.

Lisp, Jazz, Aïkido: http://www.didierverna.info
Pascal Costanza
2017-12-27 12:27:13 UTC
Permalink
Hi,
Post by Didier Verna
Hello,
there is something annoying with
ensure-generic-function-using-class. The MOP specifies that if the
:generic-function-class option is not provided, it defaults to
standard-generic-function. While this makes perfect sense when the
generic function doesn't already exist, it seems to also apply when it
does.
As a result, if you want to call ensure-generic-function on an existing
(ensure-generic-function gf-name :generic-function-class (class-of gf))
This is a bit annoying, and I don't understand the rationale behind
this, if there's one. Why not defaulting to the existing generic
function's meta-class?
ensure-generic-function is the functional version of the defgeneric macro, and is supposed to behave the same way. If you don’t pass the :generic-function-class option to the defgeneric macro, it will also default to standard-generic-function, no matter what the previous definition of the generic function was.

If you want to change only one or a few aspects of a generic function (or metaobjects in general), you are supposed to call reinitialize-instance, which leaves all properties for which no keywords are passed unchanged.

Pascal

--
Pascal Costanza
Didier Verna
2017-12-27 16:01:15 UTC
Permalink
Post by Pascal Costanza
ensure-generic-function is the functional version of the defgeneric
macro, and is supposed to behave the same way.
Makes sense. Thanks.
--
Resistance is futile. You will be jazzimilated.

Lisp, Jazz, Aïkido: http://www.didierverna.info
Martin Simmons
2018-01-02 15:15:19 UTC
Permalink
Hi,
Post by Didier Verna
Hello,
there is something annoying with
ensure-generic-function-using-class. The MOP specifies that if the
:generic-function-class option is not provided, it defaults to
standard-generic-function. While this makes perfect sense when the
generic function doesn't already exist, it seems to also apply when it
does.
As a result, if you want to call ensure-generic-function on an existing
(ensure-generic-function gf-name :generic-function-class (class-of gf))
This is a bit annoying, and I don't understand the rationale behind
this, if there's one. Why not defaulting to the existing generic
function's meta-class?
ensure-generic-function is the functional version of the defgeneric macro, and is supposed to behave the same way. If you don’t pass the :generic-function-class option to the defgeneric macro, it will also default to standard-generic-function, no matter what the previous definition of the generic function was.
I think the MOP is inconsistent about this, because the expansion of the
defmethod macro is supposed to call ensure-generic-function, but there is no
way to specify the :generic-function-class argument (I know it could look for
an existing gf, but the "possible correct expansion" in the MOP doesn't).

The definition of ensure-generic-function-using-class says:

"If the class of the generic-function argument is not the same as the class
specified by the :generic-function-class argument, an error is signaled."

It makes more sense if that only applies when the :generic-function-class
argument is supplied. That also makes it work like the other keywords,
i.e. omitting them doesn't change anything.
--
Martin Simmons
LispWorks Ltd
http://www.lispworks.com/
Loading...