Override inline function

How would I redefine an inline function while keeping a link to an old function under a different name?

those. with sbcl

(unlock-package 'common-lisp)
(defun old+ (a b) ??????
(defun + (a b) (old+ a b))

I am porting the code to a LISP implementation that does not have a floating point data type. So I wanted to redefine mathematical operations to use fixed integer math.

I can also solve this problem by searching and replacing :)

+5
source share
1 answer

To answer your specific question:

(defconstant +old-plus+ (fdefinition '+))
(defun + (&rest args) (apply +old-plus+ args))

, (, , ), : +old-plus+ + ( , ), +.

, , CL +, , CL (untested):

(rename-package "COMMON-LISP" "COMMON-LISP-ORIGINAL")
(make-package "COMMON-LISP")
(use-package "COMMON-LISP-ORIGINAL" "COMMON-LISP")
(shadow "+" "COMMON-LISP")
(do-external-symbols (s "COMMON-LISP-ORIGINAL")
  (export (find-symbol (symbol-name s)) "COMMON-LISP"))
(defun common-lisp::+ (&rest args) (apply #'common-lisp-original:+ args))

.

, , " - undefined", rename-package "COMMON-LISP-ORIGINAL".

+12

All Articles