在 Lisp 和其他使用 S 表达式作为语法的语言中,括号主要是为了编译器的利益,而布局和缩进(编译器会忽略)则是为了程序员的利益。
因此,无需在自己的行上放置右括号:精心选择的换行符和缩进足以使结构清晰。
例如,
(defun clone-indirect-buffer-other-window (newname display-flag &optional norecord)
"Like `clone-indirect-buffer' but display in another window."
(interactive
(progn
(if (get major-mode 'no-clone-indirect)
(error "Cannot indirectly clone a buffer in %s mode" mode-name))
(list (if current-prefix-arg
(read-buffer "Name of indirect buffer: " (current-buffer)))
t)))
(let ((pop-up-windows t))
(clone-indirect-buffer newname display-flag norecord)))
从缩进来看,结构很清晰(对于经验丰富的 Lisp 程序员来说)。将一些右括号放到新行上不会添加任何内容:
(defun clone-indirect-buffer-other-window (newname display-flag &optional norecord)
"Like `clone-indirect-buffer' but display in another window."
(interactive
(progn
(if (get major-mode 'no-clone-indirect)
(error "Cannot indirectly clone a buffer in %s mode" mode-name)
)
(list (if current-prefix-arg
(read-buffer "Name of indirect buffer: " (current-buffer))
)
t)
)
)
(let ((pop-up-windows t))
(clone-indirect-buffer newname display-flag norecord)
)
)
I should add that nearly all Lisp programmers use an editor that displays matching parentheses, performs automatic indentation, and provides a user interface for working direcly with balanced expressions. In Emacs, for example, there's M-( for inserting a new expression, M-) for moving past the end of the current expression, C-M-k for deleting the expression after point, and so on.
因此,Lisp 程序员永远不必用手计算括号来找出哪些匹配。
泰勒·R·坎贝尔 http://mumble.net/~campbell/scheme/style.txt雄辩地表达了这个道理:
实际的括号字符只是词汇标记,不应赋予其任何意义。 Lisp 程序员不会单独检查括号,或者(阿撒托斯禁止)计算括号的数量;相反,他们查看程序中表达的高层结构,尤其是缩进所呈现的结构。 Lisp 并不是要编写一系列串行指令;而是要编写一系列串行指令。它是通过对各个部分求和来构建复杂的结构。从各个部分组成复杂结构是 Lisp 程序的重点,这一点从 Lisp 代码中应该显而易见。在演示文稿中随意放置括号会让 Lisp 程序员感到不舒服,否则他们在大多数情况下都不会看到它们。