subj。 喜歡的東西:保存原始功能,在本地用flet重新綁定並從新裏面調用原始功能?
(lexical-let (oldf #'original-func)
(flet ((original-func (arg)
do-something
(funcall oldf arg)))
do-something))
不工作:(
subj。 喜歡的東西:保存原始功能,在本地用flet重新綁定並從新裏面調用原始功能?
(lexical-let (oldf #'original-func)
(flet ((original-func (arg)
do-something
(funcall oldf arg)))
do-something))
不工作:(
希望這將有助於你的語法,呼叫交換功能調用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)
目前在電子閱讀器沒有宏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-binding
到T
。
謝謝.. .. :) – 2012-02-05 18:28:26
哦,謝謝!不知道符號功能。 – 2012-02-05 18:29:14