elisp中下划线(_)的含义是什么?

12

我正在审查Emacs软件包中的neotree代码包。我不知道下面宏定义中下划线(_)的含义。

(lambda (&rest _))

该宏的完整定义如下。

(defmacro neotree-make-executor (&rest fn-form)
  "Make an open event handler, FN-FORM is event handler form."
  (let* ((get-args-fn
          (lambda (sym) (or (plist-get fn-form sym) (lambda (&rest _)))))
         (file-fn (funcall get-args-fn :file-fn))
         (dir-fn (funcall get-args-fn :dir-fn)))
    `(lambda (&optional arg)
       (interactive "P")
       (neo-global--select-window)
       (neo-buffer--execute arg ,file-fn ,dir-fn))))
2个回答

18

下划线是一个有效的符号名称。对于字节编译器来说,惯例是未使用的参数名称应以下划线开头,以避免在编译期间出现“未使用的词法变量”警告。


6

请参考elisp参考手册

11.9.4 使用词法绑定 ...

lexical-binding [Variable]
    If this buffer-local variable is non-nil, Emacs Lisp files and buffers are evaluated
    using lexical binding instead of dynamic binding. (However, special variables are still
    dynamically bound; see below.) If nil, dynamic binding is used for all local variables.
    This variable is typically set for a whole Emacs Lisp file, as a file local variable (see
    Section 11.11 [File Local Variables], page 163). Note that unlike other such variables,
    this one must be set in the first line of a file.

...

(To silence byte-compiler warnings about unused variables, just use a variable name that
start with an underscore. The byte-compiler interprets this as an indication that this is a
variable known not to be used.)

在最新的(撰写时尚未发布的)Emacs 28.0.50中,使用C-h i m Elisp <RET> g <Converting to Lexical Binding>进入相关的Info部分。 - Y. E.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接