我正在查看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))))
答案 0 :(得分:15)
下划线是有效的符号名称。字节编译器的约定是未使用的参数名称应以下划线开头,以避免使用"未使用的词法变量"编译时发出警告。
答案 1 :(得分:3)
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.)