为什么许多 Lisp 都有诸如“foo”、“foo-1”、“foo-2”等函数名称?
我注意到各种 Lisp(至少是 Common Lisp 和 Emacs Lisp)中的很多例子,其中两个或多个函数除了尾随数字之外具有相同的名称。例如,Emacs Lisp 有 eval-last-sexp
和 eval-last-sexp-1
。它还具有 print
和 prin1
。这似乎是一种普遍做法,但人们学习编程的第一件事就是为函数指定唯一且具有描述性的名称。这种做法从何而来?
I've noticed quite a few examples in various Lisps (at least Common Lisp and Emacs Lisp) where two or more functions had identical names except for a trailing number. For example, Emacs Lisp has eval-last-sexp
and eval-last-sexp-1
. It also has print
and prin1
. This seems to be a general practice, yet one of the first things one learns about programming is to give functions unique and descriptive names. Where does this practice come from?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
大多数情况下,这个 1 具有语义含义(通常是“单个”):
macroexpand
试图展开表单中的所有宏,而macroexpand-1
则展开只有顶级宏last1
,它返回列表的最后一个元素(因为last
返回最后一个 cons 单元格prin1
更复杂,但也不仅仅是随机加 1:有print
、princ
和prin1
code> (还有pprint
)。有关更多详细信息,请参阅 Hyperspec。Most of the times this 1 has a semantic meaning (usually, "single"):
macroexpand
that tries to expands all macros in a form, andmacroexpand-1
that expands only the top-level macrolast1
, that returns the last element of a list (aslast
returns the last cons cell)prin1
is more complicated, but as well isn't just a random addition of 1: there'sprint
,princ
andprin1
(and alsopprint
). See Hyperspec for more details.