11 2012 档案
SICP学习笔记 - 第二章 (2.4)
摘要:部分习题:exercise 2.73a)对求导过程来说,数字和变量的表示形式对任何“类型标志”(例如+)都是一致的,没有必要实现不同的表示方式。b) 1 (define (install-deriv-sum-package) 2 ;internal procedure 3 (define (addend s) (cadr s)) 4 (define (augend s) (caddr s)) 5 (define (make-sum a1 a2) 6 (cond ((=number? a1 0) a2) 7 ((=number? a2 0) a1) 8 ...
阅读全文
SICP学习笔记 - 第二章 (2.3)
摘要:基本过程:1 (eq? <symbol1> <symbol2>) ;判断连个符号是否相同2 (cadr <list>) => (car (cdr <list>))3 (number? <num>)4 (symbol? <sym>)范例:霍夫曼编码树定长编码(fixed-length codes):采用同样数目的二进制位表示消息中的每个字符。变长编码(variable-length codes):采用不同数目的二进制位表示不同字符。前缀码(prefix code):每个字符的完整编码都不是另一字符的开始一段。霍夫曼编码
阅读全文
SICP学习笔记 - 第二章 (2.2)(下)
摘要:设计原则:约定的界面(conventional interfaces)。范例:“流结构”化的 sum-odd-squares 和 even-fibs 1 (define (filter predicate sequence) 2 (cond ((null? sequence) '()) 3 ((predicate (car sequence)) 4 (cons (car sequence) 5 (filter predicate (cdr sequence)))) 6 (else (filter...
阅读全文
SICP学习笔记 - 第二章 (2.2)(上)
摘要:闭包:通过闭包组合起数据对象得到的结果本身还可以通过同样的操作再进行组合。 (In general, an operation for combining data objects ststisfies the closure property if the results of combining things with that operation can themselves be combined using the same operation.)序列(sequence):如图所示,序列由一个序对(pair)的链表(list)表示。每个序对的 car 部分对应于这个链中的条目, c.
阅读全文
SICP学习笔记 - 第二章 (2.1)
摘要:基本过程:1 (cons n d)2 (car x)3 (cdr x)部分习题:exercise 2.11 (define (make-rat n d)2 (let ((g (gcd n d)))3 (if (negative? (* n d))4 (cons (- (abs (/ n g))) (abs (/ d g)))5 (cons (abs (/ n g)) (abs (/ d g))))))exercise 2.2 1 (define (average x y) 2 (/ (+ x y) 2)) 3 (d...
阅读全文
SICP学习笔记 - 第一章 (1.3)
摘要:特殊形式(special form):1 (lambda (<formal-parameters>) <body>)2 (let ((<var1> <exp1>)3 ...4 (<varn> <expn>))5 <body>)等价形式: 1 (define (plus4 x) (+ x 4)) 2 等价于 3 (define plus4 (lambda (x) (+ x 4))) 4 5 (let ((<var1> <exp1>) 6 ... 7 (<varn> <ex
阅读全文

浙公网安备 33010602011771号