尖引号(#')与符号功能有何不同? [英] How is sharp quote (#') different from symbol-function?
问题描述
在我看来,这些运算符似乎在做同样的事情.两者都带有符号并返回与其关联的函数.有什么区别吗?
To me these operators seem to do the same thing. Both take a symbol and return the function associated with it. Is there any difference?
elisp
评估返回以下内容:
(defun foo(x)(+1 x))
foo
(foo 3)
4
#'foo
(defun foo (x) (+ 1 x))
foo
(foo 3)
4
#'foo
我都不明白.
此外,普通lisp和elisp之间有区别吗?我正在从任何一种资源中学习.
Furthermore is there a difference between common lisp and elisp? I'm learning from resources on either.
推荐答案
通用Lisp :
SYMBOL-FUNCTION
无法从词汇绑定函数中检索函数. FUNCTION
默认情况下引用词法绑定函数. #'foo
只是(FUNCTION foo)
的缩写.
SYMBOL-FUNCTION
can't retrieve functions from lexically bound functions. FUNCTION
references the lexically bound function by default. #'foo
is just a shorter notation for (FUNCTION foo)
.
CL-USER 1 > (defun foo () 'foo)
FOO
CL-USER 2 > (flet ((foo () 'bar))
(list (funcall (symbol-function 'foo))
(funcall #'foo)
(funcall (function foo))
(eq (function foo) (symbol-function 'foo))))
(FOO BAR BAR NIL)
CL-USER 3 > (eq (function foo) (symbol-function 'foo))
T
这篇关于尖引号(#')与符号功能有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!