SICP 第一章小結

--包括一些摘錄和感言,和零碎的代碼

1、要素

 

寫道
Every powerful language has three mechanisms for accomplishing this:

* 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

寫道
In general, programming languages impose restrictions on the ways in which computational elements can be manipulated. Elements with the fewest restrictions are said to have first-class status. Some of the ``rights and privileges'' of first-class elements are

* 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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章