让 elisp 中没有变量赋值的块
Let block in elisp with no variable assignments
为什么 elisp 中的 let 形式包含没有 varlist 参数的主体。示例代码,
(defun keyboard-quit ()
...............
(let (select-active-regions)
(deactivate-mark))
.........
)
这段代码是否做同样的事情,
(defun keyboard-quit ()
.......................
(select-active-regions)
(deactivate-mark)
...................................
)
此代码片段取自 simple.el
,用于 Ctrl + G 键绑定。
不,这相当于将变量绑定到nil
,即
(let (a)
(b))
与
相同
(let ((a nil))
(b))
您实际上可以从代码格式中猜到:如果您是对的,代码将被格式化为
(let
(a)
(b))
而 Emacs 将 (a)
缩进到 (b)
的右侧。
此外,这是 documented - 请参阅下面的案例 (i):
Special Form: let (bindings...) forms...
...
Each of the bindings is either (i) a symbol, in which case that symbol is locally bound to nil
; or (ii) a list of the form (symbol value-form), in which case symbol is locally bound to the result of evaluating value-form. If value-form is omitted, nil
is used.
另见 C-h f let RET:
(let VARLIST BODY...)
...
Each element of VARLIST is a symbol (which is bound to nil)
为什么 elisp 中的 let 形式包含没有 varlist 参数的主体。示例代码,
(defun keyboard-quit ()
...............
(let (select-active-regions)
(deactivate-mark))
.........
)
这段代码是否做同样的事情,
(defun keyboard-quit ()
.......................
(select-active-regions)
(deactivate-mark)
...................................
)
此代码片段取自 simple.el
,用于 Ctrl + G 键绑定。
不,这相当于将变量绑定到nil
,即
(let (a)
(b))
与
相同(let ((a nil))
(b))
您实际上可以从代码格式中猜到:如果您是对的,代码将被格式化为
(let
(a)
(b))
而 Emacs 将 (a)
缩进到 (b)
的右侧。
此外,这是 documented - 请参阅下面的案例 (i):
Special Form: let (bindings...) forms...
...
Each of the bindings is either (i) a symbol, in which case that symbol is locally bound to
nil
; or (ii) a list of the form (symbol value-form), in which case symbol is locally bound to the result of evaluating value-form. If value-form is omitted,nil
is used.
另见 C-h f let RET:
(let VARLIST BODY...)
...
Each element of VARLIST is a symbol (which is bound to nil)