Paul Graham: Essays 2024年11月25日
What Made Lisp Different
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文回顾了John McCarthy在20世纪50年代末设计Lisp语言时引入的九个创新理念,这些理念在当时是相当激进的,与Fortran等主流语言形成了鲜明对比。Lisp引入了条件语句、函数类型、递归、新的变量概念、垃圾回收机制等,并以表达式为程序的基本单位,使用符号树表示代码,以及实现语言的全面可用性。这些创新理念对现代编程语言的发展产生了深远的影响,许多理念逐渐被主流语言所吸收,例如条件语句、函数类型、递归等。虽然Lisp的语法和宏系统仍然相对独特,但它所体现的编程思想对现代编程实践产生了深远影响。

🍀 **条件语句:**Lisp首次引入了if-then-else结构,解决了Fortran时代仅有条件跳转的局限,并推动了条件语句在其他语言中的普及。

💻 **函数类型:**Lisp将函数视为一等公民,与整数、字符串等数据类型具有同等地位,可以存储在变量中、作为参数传递等,为函数式编程奠定了基础。

🔄 **递归:**Lisp是首个支持递归的编程语言,将数学概念引入编程领域,并与函数一等公民的概念紧密关联。

🔄 **新的变量概念:**Lisp中的变量本质上都是指针,类型属于值而非变量,赋值操作只是复制指针,而非值本身。

🗑️ **垃圾回收机制:**Lisp引入了垃圾回收机制,自动管理内存,减少了程序员的负担,提高了程序的可靠性。

🌳 **表达式构成的程序:**Lisp程序由表达式树构成,每个表达式都返回一个值,这与Fortran等语言区分表达式和语句的做法不同。

🔤 **符号类型:**Lisp引入了符号类型,与字符串不同,可以通过指针比较实现快速相等性判断。

🌲 **符号树表示代码:**Lisp使用符号树来表示代码,为宏系统等高级功能奠定了基础。

⏱️ **语言的全面可用性:**Lisp没有明显的读取时间、编译时间和运行时间的区别,可以在读取时编译或运行代码,编译时读取或运行代码,运行时读取或编译代码,实现了语言的灵活性和扩展性。

December 2001 (rev. May 2002)(This article came about in response to some questions onthe LL1 mailing list. It is nowincorporated in Revenge of the Nerds.)When McCarthy designed Lisp in the late 1950s, it wasa radical departure from existing languages,the most important of which was Fortran.Lisp embodied nine new ideas:1. Conditionals. A conditional is an if-then-elseconstruct. We take these for granted now. They were inventedby McCarthy in the course of developing Lisp. (Fortran at that time only had a conditionalgoto, closely based on the branch instruction in the underlying hardware.) McCarthy, who was on the Algol committee, gotconditionals into Algol, whence they spread to most otherlanguages.2. A function type. In Lisp, functions are first class objects-- they're a data type just like integers, strings,etc, and have a literal representation, can be stored in variables,can be passed as arguments, and so on.3. Recursion. Recursion existed as a mathematical conceptbefore Lisp of course, but Lisp was the first programming language to supportit. (It's arguably implicit in making functions first classobjects.)4. A new concept of variables. In Lisp, all variablesare effectively pointers. Values are whathave types, not variables, and assigning or bindingvariables means copying pointers, not what they point to.5. Garbage-collection.6. Programs composed of expressions. Lisp programs are trees of expressions, each of which returns a value. (In some Lisps expressionscan return multiple values.) This is in contrast to Fortranand most succeeding languages, which distinguish betweenexpressions and statements.It was natural to have thisdistinction in Fortran because (not surprisingly in a languagewhere the input format was punched cards) the language wasline-oriented. You could not nest statements. Andso while you needed expressions for math to work, there wasno point in making anything else return a value, becausethere could not be anything waiting for it.This limitationwent away with the arrival of block-structured languages,but by then it was too late. The distinction betweenexpressions and statements was entrenched. It spread from Fortran into Algol and thence to both their descendants.When a language is made entirely of expressions, you cancompose expressions however you want. You can say either(using Arc syntax)(if foo (= x 1) (= x 2))or(= x (if foo 1 2))7. A symbol type. Symbols differ from strings in thatyou can test equality by comparing a pointer.8. A notation for code using trees of symbols.9. The whole language always available. There isno real distinction between read-time, compile-time, and runtime.You can compile or run code while reading, read or run codewhile 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; compilingat runtime is the basis of Lisp's use as an extensionlanguage in programs like Emacs; and reading at runtimeenables programs to communicate using s-expressions, anidea recently reinvented as XML.When Lisp was first invented, all these ideas were farremoved from ordinary programming practice, which wasdictated largely by the hardware available in the late 1950s.Over time, the default language, embodiedin a succession of popular languages, hasgradually evolved toward Lisp. 1-5 are now widespread.6 is starting to appear in the mainstream.Python has a form of 7, though there doesn't seem to beany syntax for it. 8, which (with 9) is what makes Lisp macrospossible, 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, you can no longer claim to have invented a new language, but onlyto have designed a new dialect of Lisp ; -)Though useful to present-day programmers, it'sstrange to describe Lisp in terms of itsvariation from the random expedients other languagesadopted. That was not, probably, how McCarthythought of it. Lisp wasn't designed to fix the mistakesin Fortran; it came about more as the byproduct of anattempt to axiomatize computation.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Lisp 编程语言 Fortran 函数式编程
相关文章