What Made Lisp Different
December 2001 (rev.
2001 年 12 月(修订版)
May 2002) (This article came about in response to some questions on the LL1 mailing list.
2002 年 5 月)(本文是为了回答 LL1 邮件列表上的一些问题而写的。
It is now incorporated in Revenge of the Nerds .) When McCarthy designed Lisp in the late 1950s, it was a radical departure from existing languages, the most important of which was Fortran .
它现在已被纳入《书呆子的复仇》中。)当 McCarthy 在 20 世纪 50 年代末设计 Lisp 时,它与现有语言(其中最重要的是 Fortran)截然不同。
Lisp embodied nine new ideas: 1.
Lisp 体现了九个新思想: 1.
Conditionals.
条件句。
A conditional is an if-then-else construct.
条件是 if-then-else 结构。
We take these for granted now.
我们现在认为这些是理所当然的。
They were
他们是
invented by McCarthy in the course of developing Lisp.
麦卡锡在开发 Lisp 的过程中发明的。
(Fortran at that time only had a conditional goto, closely based on the branch instruction in the underlying hardware.) McCarthy, who was on the Algol committee, got conditionals into Algol, whence they spread to most other languages.
(当时的 Fortran 只有条件 goto,紧密基于底层硬件中的分支指令。)Algol 委员会成员的麦卡锡将条件语句引入了 Algol,从那里它们传播到了大多数其他语言。
2.
2.
A function type.
一个函数类型。
In Lisp, functions are first class objects-- they're a data type just like integers, strings,
在 Lisp 中,函数是第一类对象——它们是一种数据类型,就像整数、字符串、
etc, and have a literal representation, can be stored in variables, can be passed as arguments, and so on.
等,并且具有文字表示,可以存储在变量中,可以作为参数传递,等等。
3.
3.
Recursion.
递归。
Recursion existed as a mathematical concept before Lisp of course, but Lisp was the first programming language to support it.
当然,递归在 Lisp 之前就作为数学概念存在,但 Lisp 是第一个支持它的编程语言。
(It's arguably implicit in making functions first class objects.) 4.
(可以说,它隐含地使函数成为第一类对象。) 4.
A new concept of variables.
变量的新概念。
In Lisp, all variables are effectively pointers.
在 Lisp 中,所有变量实际上都是指针。
Values are what
价值观是什么
have types, not variables, and assigning or binding variables means copying pointers, not what they point to.
有类型,没有变量,分配或绑定变量意味着复制指针,而不是它们指向的内容。
5.
5.
Garbage-collection.
垃圾收集。
6.
6.
Programs composed of expressions.
由表达式组成的程序。
Lisp programs are trees of expressions, each of which returns a value.
Lisp 程序是表达式树,每个表达式都返回一个值。
(In some Lisps expressions can return multiple values.) This is in contrast to Fortran and most succeeding languages, which distinguish between expressions and statements.
(在某些 Lisp 中,表达式可以返回多个值。)这与 Fortran 和大多数后续语言形成对比,它们区分表达式和语句。
It was natural to have this distinction in Fortran because (not surprisingly in a language where the input format was punched cards) the language was line-oriented.
Fortran 中存在这种区别是很自然的,因为(对于输入格式为打孔卡的语言来说并不奇怪)该语言是面向行的。
You could not nest statements.
您不能嵌套语句。
And so while you needed expressions for math to work, there was no point in making anything else return a value, because there could not be anything waiting for it.
因此,虽然您需要数学表达式才能工作,但让其他任何东西返回值是没有意义的,因为没有任何东西在等待它。
This limitation went away with the arrival of block-structured languages,
随着块结构语言的出现,这种限制消失了,
but by then it was too late.
但那时已经太晚了。
The distinction between expressions and statements was entrenched.
表达式和陈述之间的区别是根深蒂固的。
It spread from Fortran into Algol and thence to both their descendants.
它从 Fortran 传播到 Algol,然后再传播到它们的后代。
When a language is made entirely of expressions, you can compose expressions however you want.
当语言完全由表达式组成时,您可以随心所欲地组合表达式。
You can say either (using Arc syntax) (if foo (= x 1) (= x 2)) or (= x (if foo 1 2)) 7.
您可以说(使用 Arc 语法)(if foo (= x 1) (= x 2)) 或 (= x (if foo 1 2)) 7。
A symbol type.
符号类型。
Symbols differ from strings in that
符号与字符串的不同之处在于
you can test equality by comparing a pointer.
您可以通过比较指针来测试相等性。
8.
8.
A notation for code using trees of symbols.
使用符号树的代码表示法。
9.
9.
The whole language always available.
整个语言始终可用。
There is no real distinction between read-time, compile-time, and runtime.
读取时、编译时和运行时之间没有真正的区别。
You can compile or run code while reading, read or run code while compiling, and read or compile code at runtime.
您可以在读取时编译或运行代码,在编译时读取或运行代码,以及在运行时读取或编译代码。
Running code at read-time lets users reprogram Lisp's syntax; running code at compile-time is the basis of macros; compiling
在读取时运行代码可以让用户重新编程 Lisp 的语法;在编译时运行代码是宏的基础;编译
at runtime is the basis of Lisp's use as an extension language in programs like Emacs; and reading at runtime enables programs to communicate using s-expressions, an idea recently reinvented as XML.
在运行时是 Lisp 在 Emacs 等程序中用作扩展语言的基础;在运行时读取使程序能够使用 s 表达式进行通信,这一想法最近被重新发明为 XML。
When Lisp was first invented, all these ideas were far removed from ordinary programming practice, which was dictated largely by the hardware available in the late 1950s.
当 Lisp 首次发明时,所有这些想法都与普通编程实践相去甚远,而普通编程实践很大程度上是由 20 世纪 50 年代末可用的硬件决定的。
Over time, the default language, embodied
随着时间的推移,默认语言体现
in a succession of popular languages, has gradually evolved toward Lisp.
在一系列流行语言中,已经逐渐向 Lisp 演变。
1-5 are now widespread.
1-5现在已经很普遍了。
6 is starting to appear in the mainstream.
6开始出现在主流中。
Python has a form of 7, though there doesn't seem to be any syntax for it.
Python 的形式为 7,但似乎没有任何语法。
8, which (with 9) is what makes Lisp macros possible, is so far still unique to Lisp, perhaps because (a) it requires those parens, or something just as bad, and (b) if you add that final increment of power,
8(和 9)使 Lisp 宏成为可能,到目前为止仍然是 Lisp 所独有的,也许是因为(a)它需要那些括号,或者同样糟糕的东西,以及(b)如果你添加最后的幂增量,
you can no longer claim to have invented a new language, but only to have designed a new dialect of Lisp ; -) Though useful to present-day programmers, it's strange to describe Lisp in terms of its variation from the random expedients other languages adopted.
你不能再声称发明了一种新语言,而只能声称设计了一种新的 Lisp 方言; -) 虽然对当今的程序员很有用,但用与其他语言所采用的随机权宜之计的变化来描述 Lisp 是很奇怪的。
That was not, probably, how McCarthy thought of it.
麦卡锡可能不是这么想的。
Lisp wasn't designed to fix the mistakes in Fortran; it came about more as the byproduct of an
Lisp 的设计初衷并不是为了修复 Fortran 中的错误;它更多地是作为一个副产品出现的
attempt to axiomatize computation .
尝试将计算公理化。
<!-- Nor is this a complete list of ideas that began with Lisp and spread to other languages.
<!-- 这也不是始于 Lisp 并传播到其他语言的完整想法列表。
These are only the initial set.
这些只是初始设置。
Several more were developed in successive Lisp implementations, including continuations, multiple return values, rest parameters, and assignment (setf) inversion.
在连续的 Lisp 实现中还开发了更多的功能,包括延续、多个返回值、剩余参数和赋值 (setf) 反转。
-->
-->