--包括一些摘錄和感言,和零碎的代碼
1、要素
* primitive expressions , which represent the simplest entities the language is concerned with,
* means of combination , by which compound elements are built from simpler ones, and
* means of abstraction , by which compound elements can be named and manipulated as units.
重點在於combination和abstraction, 我覺得FP將function也作爲元素,使得它可以進一步的組合,這樣在抽象和結合的能力上更進了一步。
2、First-class elements
* They may be named by variables.
* They may be passed as arguments to procedures.
* They may be returned as the results of procedures.
* They may be included in data structures.
FP語言中函數是作爲First-class elements,相比於常用的c,c++,pascal,java...命令式語言中函數只是一種數據的結合和抽象的方式,函數在裏面不能作爲參數和結果,當然也不能包含在數據結構中,只是將數據結構和之上的運算用類封裝在了一起。
FP的優勢當然就是更強大的抽象能力,這還需要多多體會。
3、Substitution Model for Procedure Application
一種分析的方式
4、Higher-Order Procedure
除了前面提到的能力,多了一個匿名函數的概念,我主要是認爲它使得函數變得更靈活,如同基本數據一樣。
5、Recursion VS Iteration
需要體會二者的聯繫與轉換,後者在命令式語言中一般可以用for表示。迭代不會改善時間複雜度,節約空間,相比速度會有一些提高。
6、算法
A. Exponentiation
O(n)
a1. Recurse version
a2. Iterate version
O(logn)
b1. Recurse version
b2. Iterate version
B. GCD
C. Testing for Primality
a.試除法
b.Miller-Rabin Test