[Openmcl-devel] Redefining Mathematical Operators?

Robert Goldman rpgoldman at sift.net
Thu Jul 9 14:41:45 PDT 2015


On 7/9/15 Jul 9 -4:37 PM, Steven Núñez wrote:
> 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?


I believe what you should probably do is SHADOW these operators in a
different package, and do your generic-function-ifying in that package
(or something that uses that package in a way that also shadows the CL
built-ins).

cheers,
r





More information about the Openmcl-devel mailing list