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

你可能感兴趣的:(数据结构,c,算法,FP,pascal)