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?
Hi,
On 27 Dec 2017, at 12:50, Didier Verna didier@lrde.epita.fr wrote:
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?
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
Pascal Costanza wrote:
ensure-generic-function is the functional version of the defgeneric macro, and is supposed to behave the same way.
Makes sense. Thanks.
On Wed, 27 Dec 2017 13:27:13 +0100, Pascal Costanza said:
Hi,
On 27 Dec 2017, at 12:50, Didier Verna didier@lrde.epita.fr wrote:
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?
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.