(我写这篇文章是为了帮自己弄清楚 McCarthy 究竟发现了什么。日常用 Lisp 编程并不需要了解这些,但对于任何想理解 Lisp 本质的人——无论就其起源还是其语义核心而言——这都应该有所启发。拥有这样一个核心正是 Lisp 的显著特征之一,也是它与其他语言不同、拥有诸多方言的原因。)
(I wrote this article to help myself understand exactly what McCarthy discovered. You don't need to know this stuff to program in Lisp, but it should be helpful to anyone who wants to understand the essence of Lisp — both in the sense of its origins and its semantic core. The fact that it has such a core is one of Lisp's distinguishing features, and the reason why, unlike other languages, Lisp has dialects.)
1960 年,约翰·麦卡锡发表了一篇非凡的论文,他在编程领域所做的工作,堪比欧几里得在几何学中所做的一切。他展示了如何仅凭几个简单的运算符和一种函数表示法,就能构建出一门完整的编程语言。他将这门语言命名为 Lisp,即“列表处理”(List Processing)的缩写,因为他的核心想法之一就是使用一种名为“列表”(list)的简单数据结构来同时表示代码和数据。
In 1960, John McCarthy published a remarkable paper in which he did for programming something like what Euclid did for geometry. He showed how, given a handful of simple operators and a notation for functions, you can build a whole programming language. He called this language Lisp, for "List Processing," because one of his key ideas was to use a simple data structure called a list for both code and data.
理解麦卡锡的发现是非常有价值的,这不仅因为它是计算机历史上的一个里程碑,更因为它为我们这个时代编程的发展趋势提供了一个典范。在我看来,迄今为止只有两种真正清晰、一致的编程模型:C 模型和 Lisp 模型。这两者就像是两座高峰,中间隔着一片泥泞的低谷。随着计算机变得越来越强大,新开发出来的语言一直在稳步迈向 Lisp 模型。过去 20 年里,设计新编程语言的一个流行配方就是:采用 C 语言的计算模型,然后零敲碎打地从 Lisp 模型中借鉴一些元素,比如运行时类型检查和垃圾回收。
It's worth understanding what McCarthy discovered, not just as a landmark in the history of computers, but as a model for what programming is tending to become in our own time. It seems to me that there have been two really clean, consistent models of programming so far: the C model and the Lisp model. These two seem points of high ground, with swampy lowlands between them. As computers have grown more powerful, the new languages being developed have been moving steadily toward the Lisp model. A popular recipe for new programming languages in the past 20 years has been to take the C model of computing and add to it, piecemeal, parts taken from the Lisp model, like runtime typing and garbage collection.
在这篇文章中,我打算用最通俗易懂的语言来解释 McCarthy 究竟发现了什么。目的不仅是去了解四十年前有人推导出的一个有趣的理论成果,而是要看清编程语言的发展方向。Lisp 的与众不同之处——事实上,也是 Lisp 的决定性特质——在于它可以用自身来编写。为了理解 McCarthy 这话的含义,我们将沿着他的足迹重走一遍,把他的数学记号转化为可运行的 Common Lisp 代码。
In this article I'm going to try to explain in the simplest possible terms what McCarthy discovered. The point is not just to learn about an interesting theoretical result someone figured out forty years ago, but to show where languages are heading. The unusual thing about Lisp — in fact, the defining quality of Lisp — is that it can be written in itself. To understand what McCarthy meant by this, we're going to retrace his steps, with his mathematical notation translated into running Common Lisp code.