Skip to content

Lisp

在学习symbolic programming时,阅读了utexas CS 378: Symbolic ProgrammingLecture Notes中主要介绍了Lisp系列语言,引起了我的好奇;然后今天(20201102)在学习lambda calculus的时候,阅读csdn 神奇的λ-calculus 时,其中也有对Lisp的描述:

相比今天各种流行程序语言中具有的以及时不时要新增的时髦语法和概念,基于λ-calculus发明的Lisp之流几乎让人觉得特别落后了(实际并不是这样,《黑客与画家》有对Lisp的高度褒奖,以及SICP使用Scheme,丹尼尔所著的各种Scheme书籍都是对Lisp的高度肯定)(Scheme是Lisp的一种方言)。

所以决定对Lisp系列语言进行学习。

wikipedia Lisp (programming language)

Lisp (historically LISP) is a family of programming languages with a long history and a distinctive, fully parenthesized prefix notation.[3] Originally specified in 1958, Lisp is the second-oldest high-level programming language in widespread use today. Only Fortran is older, by one year.[4][5] Lisp has changed since its early days, and many dialects have existed over its history. Today, the best-known general-purpose Lisp dialects are Racket, Common Lisp, Scheme and Clojure.

NOTE:

1、prefix notation 指的是 前缀表达式

Lisp was originally created as a practical mathematical notation (数学符号) for computer programs, influenced by (though not originally derived from [6]) the notation of Alonzo Church's lambda calculus. It quickly became the favored programming language for artificial intelligence (AI) research. As one of the earliest programming languages, Lisp pioneered many ideas in computer science, including tree data structures, automatic storage management, dynamic typing, conditionals, higher-order functions, recursion, the self-hosting compiler,[7] and the read–eval–print loop.[8]

NOTE: 通过Lisp也可以看出programming language的发展史。

关于lambda calculus,参见工程discrete的Relation-structure-computation\Computation\Theory-of-computation\Model-of-computation\Lambda-calculus章节。

mathematical notation 的意思是 "数学符号",其实就是symbol。

The name LISP derives from "LISt Processor"(列表处理器).[9] Linked lists are one of Lisp's major data structures, and Lisp source code is made of lists. Thus, Lisp programs can manipulate source code as a data structure, giving rise to the macro systems that allow programmers to create new syntax or new domain-specific languages embedded in Lisp.

NOTE: 最后一段所描述的其实就是symbolic programming,它让programmer实现创建DSL。在现代programming language中,有很多时候,都需要这种能力。

The interchangeability of code and data gives Lisp its instantly recognizable syntax. All program code is written as s-expressions, or parenthesized lists. A function call or syntactic form is written as a list with the function or operator's name first, and the arguments following; for instance, a function f that takes three arguments would be called as (f arg1 arg2 arg3).

NOTE: s-expression就是symbolic expression,它是Lisp系列语言的核心。

History

John McCarthy developed Lisp in 1958 while he was at the Massachusetts Institute of Technology (MIT). McCarthy published its design in a paper in Communications of the ACM in 1960, entitled "Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I".[10] He showed that with a few simple operators and a notation for anonymous functions borrowed from Church, one can build a Turing-complete language for algorithms.

NOTE: 上面这段话中的**anonymous functions**,其实就是lambda function。

Genealogy and variants

NOTE: 家系和变体

Over its sixty-year history, Lisp has spawned many variations on the core theme of an S-expression language.

NOTE: Lisp系列语言的核心是: S-expression language

Syntax and semantics

Symbolic expressions (S-expressions)

Lisp is an expression oriented language. Unlike most other languages, no distinction is made between "expressions" and "statements";[dubiousdiscuss] all code and data are written as expressions. When an expression is evaluated, it produces a value (in Common Lisp, possibly multiple values), which can then be embedded into other expressions. Each value can be any data type.

McCarthy's 1958 paper introduced two types of syntax: Symbolic expressions (S-expressions, sexps), which mirror the internal representation of code and data; and Meta expressions (M-expressions), which express functions of S-expressions. M-expressions never found favor, and almost all Lisps today use S-expressions to manipulate both code and data.

Lists

NOTE: 使用List来表示expression tree

Expressions are written as lists, using prefix notation.

Operators

Lambda expressions and function definition

Conses and lists

Main article: Cons

A Lisp list is implemented as a singly linked list.[55] Each cell of this list is called a cons (in Scheme, a pair), and is composed of two pointers, called the car and cdr. These are respectively equivalent to the data and next fields discussed in the article linked list.