[Openmcl-devel] Redefining Mathematical Operators?
Steven Núñez
steven.nunez at illation.com
Thu Jul 9 14:37:57 PDT 2015
Greetings fellow Clozurians,
I have a legacy codebase in xlisp-stat and to run on CCL I need to redefine the mathematics operators to work on both numbers and lists. Ideally I'd be able to do something like this:
(defgeneric + (x y))
(defmethod + ((x number) (y number)) ...) ; Add x to y
(defmethod + ((x number) (y list)) ...) ; Add x to every element of y
(defmethod + ((x list) (y list)) ...) ; Add elements of x and y pairwise
However '+' isn't a generic function:
? (defmethod + ((x number) (y number)) t)
> Error: The function + is defined as something other than a generic function.
> While executing: ENSURE-GENERIC-FUNCTION, in process listener(1).
so I thought I would undefine it and then redefine it as a generic. Something like this:
(defparameter *+* #'+) ; Save + for later use
(fmakunbound '+) ; Undefine it so we can use a multi-method
(defgeneric + (x y))
(defmethod + ((x number) (y number))
(funcall *+* x y))
But it looks like the '+' operator is used somewhere in the compiler:
? (defgeneric + (x y))
> Error: Undefined function + called with arguments (0 8) . signaled during assembly-time evaluation of form (+ 0 8)
> While executing: CCL::PARSE-X86-LAP-EXPRESSION, in process listener(1).
Has anyone got any ideas how to redefine these operators? I supposed a bit of macro-magic might do the trick, but I thought I'd ask here to see if anyone has done anything like this before and if there's anything I should watch out for if I have to go the macro route?
Regards,
- Steve Nunez
More information about the Openmcl-devel
mailing list