Emacs:函数符号前面的“#”是什么意思?

时间:2016-11-27 10:59:51

标签: emacs

例如:(add-hook 'after-init-hook #'global-flycheck-mode)

为什么需要将#添加到'global-flycheck-mode

1 个答案:

答案 0 :(得分:1)

#'只是使用function的简写。来自elisp手册:

-- Special Form: function function-object
   This special form returns FUNCTION-OBJECT without evaluating it.
   In this, it is similar to ‘quote’ (see Quoting).  But unlike
   ‘quote’, it also serves as a note to the Emacs evaluator and
   byte-compiler that FUNCTION-OBJECT is intended to be used as a
   function.  Assuming FUNCTION-OBJECT is a valid lambda expression,
   this has two effects:

      • When the code is byte-compiled, FUNCTION-OBJECT is compiled
        into a byte-code function object (see Byte Compilation).

      • When lexical binding is enabled, FUNCTION-OBJECT is converted
        into a closure.  See Closures.

您可以在字节编译/加载此

时看到差异
 (setq f1 '(lambda (x) (* x x)))
 (setq f2 #'(lambda (x) (* x x)))

只有正确引用的表单是字节编译的:

(byte-code-function-p f1)
nil
(byte-code-function-p f2)
t