How would i redefine a built-in function, while keeping a reference to the old function under a different name?
ie with SBCL
(unlock-package 'common-lisp)
(defun old+ (a b) ??????
(defun + (a b) (old+ a b))
I'm porting code to a LISP implementation that doesn't have float data type. So I wanted to redefine the the math ops to use fixed integer math.
I suppose i can solve this problem with search-and-replace as well :)
To answer your specific question:
Note that if you evaluate this again (e.g., by reloading the file where this code contained), you might have a problem:
+old-plus+
might get silently redefined to your new+
(or you might get an error, or you might get a warning) and you will lose the original+
definition.Therefore it seems that a better approach would be to create a new package where all symbols are imported from
CL
except for+
which is shadowed, and then use that package instead ofCL
(untested):Now you should be able to process the code.
Note that you should not load the above code twice because "consequences are undefined" if you
rename-package
to an existing"COMMON-LISP-ORIGINAL"
.