9. 语法-续
●
S and M
– S-expression
●
树结构的数据格式表示形式。有形式化的文档描述,一
个没有通过的 RFC ,地址:
http://people.csail.mit.edu/rivest/Sexp.txt
●
用于通讯数据。
●
John McCarthy 最先提到。
10. 语法-续
●
S and M
– 岔路
●
Dennis Ritchie found dead 2011.10.12
●
John McCarthy 2011.10.24
●
Steve Jobs 2011.10.05
– 第一代计算机科学家正在离开 (Jobs 不算 )
11. 语法-续
S M
(QUOTE A B C) (A B C)
(CAR X) car[x]
(CAR (APPEND (QUOTE (A B C)) car[append[(A B C); (D E F)]]
(QUOTE (D E F))))
13. 语法-续-高阶函数
●
Map Reduce
– http://www.cs.cornell.edu/courses/cs3110/2009sp/lectures/lec05.html
●
Google 与 Hadoop
– 良好的数据操作的抽象,可以作为一个通用的大规模数据处理框架,因
为可以并行。 80 年代末就存在了使用这一抽象的并行系统 The Connection
Machine 。但是时机对于技术的影响极大,有其自己的进化路径, Google
将其发扬光大, Hadoop 作为 Google 的 Map reduce 的开源实现,目前已经
被被广泛应用。
– "Our abstraction is inspired by the map and reduce primitives present in Lisp and
many other functional languages. We realized that most of our computations involved
applying a map operation to each logical record in our input in order to compute a set
of intermediate key/value pairs, and then applying a reduce operation to all the
values that shared the same key in order to combine the derived data appropriately."
15. 语法-续-高阶函数
●
Map(func list)
–将 list 中的每个元素都经过 func 进行操作,形成新的一个 list 。
其实也可以同时操作多个 list, 相对的 func 就需要同时传入多个
参数。
●
Reduce(func init list)
– func 接受两个参数,以此遍历 list ,刚开始传入的是 list 的第一和
第二项,然后通过 func 计算返回值,作为下次迭代传入的第一
个参数。如有 init ,第一次传入的为 init 和 list 第一个项。
●
Map 可以被 Reduce 来实现
16. 语法-续
●
call-by-value or call-by-name
– http://www.cs.columbia.edu/~sedwards/classes/201
0/w4115-spring/functional.pdf
●
Applicative or Normal Order
19. 示例与程序
●
小陶上次的字符组合程序
– basic 、 memoize 、 laziness
– 见代码
●
python 的 FP 风格玩具快排
– q=lambda s:s if len(s)<2 else q([x for x in s[1:]if
x<s[0]])+[s[0]]+q([x for x in s[1:]if x>=s[0]]
20. 示例与程序
●
Purely Functional Data Structures until 1998
– http://www.cs.cmu.edu/~rwh/theses/okasaki.pdf
●
New Data Structures since 1998
– http://cstheory.stackexchange.com/questions/1539/
whats-new-in-purely-functional-data-structures-si
nce-okasaki
21. 嵌入式语言实现、解释器
●
eval
– Racket <- Scheme
– 资料来源
●
https://class.coursera.org/proglang-2012-001/class/index
●
bootstrap scheme
– 1700 lines c
– 尾递归最后转换为迭代
●
Java 的伪递归构建
– 《 The Role of the Study of Programming Languages in the Education of
a Programmer 》
25. 引用资料
●
Lisp 历史
– History of Lisp by John McCarthy
●
http://www-formal.stanford.edu/jmc/history/lisp/lisp.html
– History of Lisp by Paul Graham and also On Lisp
●
http://www.paulgraham.com/lisphistory.html
●
On Lisp ,有中文翻译版本。
●
书籍
– Paradigms of Artificial Intelligence Programming: Case Studies in Common
Lisp by Peter Norvig
●
http://norvig.com/paip.html
– Concepts, Techniques, and Models of Computer Programming
●
http://www.info.ucl.ac.be/~pvr/book.html
26. 引用资料
●
elisp 教程
– By GNU
●
http://www.gnu.org/software/emacs/emacs-lisp-intro/htm
l_node/index.html
– By Xah
●
http://ergoemacs.org/emacs/elisp.html