sicp note

  1. there are techniques for controlling the complexity of these large systems.

  2. 控制复杂度是《代码大全》里面反复强调的技术

  3. First technique, which is used in all of engineering is a kind of abstraction called black-box abstraction.

  4. I might take that and build a box.

  5. That sort of says, to find the square root of X. just black box

  6. box box box black box, we don't care how result comes out, we only care about the result

  7. So that we can build another bigger box.

imperative knowledge "HOW TO"

TO FIND AN APPROXIMATION TO √x

KEEP APPROVING IT

  • MAKE A GUESS G
  • IMPROVE THE GUESS BY AVERAGING G AND X/G
  • KEEP IMPROVING THE GUESS UNTIL IT IS GOOD ENOUGH

METHOD FOR FINDING A FIXED POINT OF A FUNCTION F(THAT IS, A VALUE Y SUCH THAT F(Y) = Y)

  • START WITH A GUESS FOR Y
  • KEEP APPLYING F OVER AND OVER UNTIL THE RESULT DOESN'T CHANGE VERY MUCH.
  • EXAMPLE
    • TO COMPUTE √x, FIND A FIXED POINT OF THE FUNCTION Y AVERAGE OF Y AND X/Y

BLACK - BOX ABSTRACTION

  • PRIMITIVE OBJECTS
    • PRIMITIVE PROCEDURES
    • PRIMITIVE DATA
  • MEANS OF COMBINATION
    • PROCEDURE COMPOSITION
    • CONSTRUCTION OF COMPOUND DATA
  • MEANS OF ABSTRACTION
    • PROCEDURE DEFINITION
    • SIMPLE DATA ABSTRACTION
  • CAPTURING COMMON PATTERNS
    • HIGH-ORDER PROCEDURES
    • DATA AS PROCEDURES

CONVENTIONAL INTERFACES

  • GENERIC OPERATIONS
  • LARGE-SCALE STRUCTURE AND MODULARITY
  • OBJECT-ORIENTED PROGRAMMING
  • OPERATIONS ON AGGREGATES

META-LINGUISTIC ABSTRACTION

  • INTERPRETATION
    • APPLY-EVAL
  • EXAMPLE-LOGIC PROGRAMMING
  • REGISTER MACHINES

sicp的三大主题

1. Black-box Abstraction

2. Conventional Interfaces

3. Metalinguistic Abstraction

当有人向你介绍一门新语言的时候 / 学习新语言的时候:

你就应该问:

What is the orimitive elements of that language?

then, What are the ways you put those together?

What are the means of combination?

What are the things that allow you to take these primitive elements and build bigger things out of them?

What are the ways of putting thins together?

What are the means of abstraction?

How do we take thos complicated thins and draw those boxes around them?

How do we name them so that we can now use them as if they were primitive elements in making still more complex thins?

LISP

prefix notation

Combination

// 前缀表示法,意思就是操作符在操作数的最左端

3 17.4 5

(+ 3 17.4 5) => 25.4

Operator Operands Combinations(组合式) =》 Result

LIsp 不能瞎几把写括号,括号会被认为是一个 Operands

(+ 3 (* 5 6) 8 2) => 43

Forming combinations is the basic needs of combination that we'll be looking at.

// 后序我们将看到构造组合式是组合的基本需求

define

(DEFINE A (* 5 5)) => 25

(* A A) => 625

(DEFINE B (+ A (* 5 A))) => 150

=> general idea => function(??? 我理解是抽出 function)

(DEFINE (SQUARE X) (* X X))

(SQUARE 10) => 100

(DEFINE SQUARE (LAMBDA (x) (* x x)))

// SQUARE procedure

// syntactic sugar

the person defining mean square doesn't have to know, at this point, whether square was somethins built into the language or whether it was a procedure that was defined, that is key thing in lisp

you can't do not make arbitrary distinctions between things that happen to be primitive in the language and thins that happen to be built in.

abs(x)

(DEFINE (ABS X)

​ (COND ((< X 0)(- X))

​ ((= x 0) 0)

​ ((> X 0) X)))`

Applicative order VS Normal order

applicative order

(define (square x) (* x x))
(define (sum-of-squares x y)
  (+ (square x) (square y)))
(define (f a)
  (sum-of-squares (+ a 1) (* a 2)))

我们来计算(f 5 )

retrieving the body of f:

(sum-of-squares (+ a 1) (* a 2))

Then we replace the formal parameter a by the argument 5:

(sum-of-squares (+ 5 1) (* 5 2))

就是先计算 Operand 和 Operator,获得 combination,然后将 combination 作为一个单元再次进行计算。

normal order

(sum-of-squares (+ 5 1) (* 5 2))
(+ (square (+ 5 1)) 
   (square (* 5 2)))
(+ (* (+ 5 1) (+ 5 1)) 
   (* (* 5 2) (* 5 2)))

followed by the reductions

(+ (* 6 6) 
   (* 10 10))
(+ 36 100)

就是先把所有的参数替换进去,然后再进行计算。

fully expand and then reduce

On the other hand, normal-order evaluation can be an extremely valuable tool

原文地址:https://www.cnblogs.com/ssaylo/p/13603923.html