2012-02-05 67 views

回答

1

希望这将有助于你的语法,呼叫交换功能调用foo1但执行foo2的

你可以这样写一个。有用的宏观与替换功能与新功能的同时执行你传递一个体结合老功能。

(defun foo1() 
    (insert "hi foo1")) 

(defun foo2() 
    (insert "hi foo2")) 

(defun swap-function(old new) 
    (let ((save-func (symbol-function old))) 
    (fset old (symbol-function new)) 
    (funcall old) 
    (fset old save-func))) 

(swap-function #'foo1 #'foo2) 
+0

哦,谢谢!不知道符号功能。 – 2012-02-05 18:29:14

1

目前在电子阅读器没有宏macs-lisp,您需要明确使用 symbol-function

(defun test-1 (x) 
    (message "base test %s" x)) 

(let ((old-test-1 (symbol-function 'test-1)) 
     (z 10)) 
    (flet ((test-1 (y) 
      (funcall old-test-1 y) 
      (message "extended test %s" y))) 
    (nic-test-1 z))) 

如果你想使用它作为一个封闭你需要使用的lexical-let 代替let或设置lexical-bindingT

+0

谢谢.. .. :) – 2012-02-05 18:28:26