
Scheme
_海阔天空
这个作者很懒,什么都没留下…
展开
-
练习1.1-练习1.9
1. 练习1.1这个题没有什么好说的了,只要把代码敲出来,运行一遍就可以了。2. 练习1.2这个题应该不算难吧,没有看过别人的答案,我把我的贴出来吧。(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5))))) (* 3 (- 6 2) (- 2 7)))3.练习1.3我的方法是求出3个数的和,再将减去最小的数,算不上最好的方法吧,马马虎虎。(def原创 2014-01-06 21:20:53 · 661 阅读 · 0 评论 -
练习1.23-练习1.30
1.练习1.23改后的代码如下:(define (find-divisor-better n a) (cond ((> (square a) n) n) ((divides?-better n a) a) (else (find-divisor-better n (next-2 a)))))(define (next-2 n) (if (= 2 n) (+ 1原创 2014-01-20 20:10:43 · 618 阅读 · 0 评论 -
练习2.41-练习2.47
1.练习2.41(define (seprate-except x except) (filter (lambda (couple) (let ((first (car couple)) (second (cadr couple))) (and (not (= first except))原创 2014-01-20 18:59:14 · 697 阅读 · 0 评论 -
练习2.21-练习2.35
1.练习2.21(define (square-list items) (if (null? items) '() (cons (square (car items)) (square-list (cdr items)))))(define (square-list items) (map (lambda (x) (square x)) items))2原创 2014-01-20 20:10:25 · 673 阅读 · 0 评论 -
练习2.11-练习2.20
1.练习2.11(define (mul-interval x y) (let ((x1 (lower-bound x)) (x2 (upper-bound x)) (y1 (lower-bound y)) (y2 (upper-bound y))) (let ((zzx (and (>= x1 0) (>= x2 0))) (zzy (and (>= y1 0) (>原创 2014-01-17 21:42:30 · 597 阅读 · 0 评论 -
练习2.53-练习2.56
1.练习2.53'(a b c)'((george))'((y1 y2))'(y1 y2)#f#f'(red shoes blue socks)2.练习2.54(define (equal? s1 s2) (cond ((and (null? s1) (null? s2)) true) ((or (null? s1) (null? s原创 2014-01-23 19:10:57 · 602 阅读 · 0 评论 -
练习2.2-练习2.10
1.练习2.2(define (make-segment start end) (cons start end))(define (start-segment seg) (car seg))(define (end-segment seg) (cdr seg))(define (make-point x y) (cons x y))(define (x-poin原创 2014-01-15 21:29:45 · 608 阅读 · 0 评论 -
练习2.1
1.练习2.1(define (check-pos-neg a b) (or (and (not ( b 0)) (and (not (> a 0)) (< b 0))))(define (make-rat n d) (let ((g (gcd (abs n) (abs d))) (posi (check-pos-neg n d))) (cons (/ (if原创 2014-01-14 22:59:32 · 529 阅读 · 0 评论 -
练习2.48-练习2.51
1.练习2.48(define (make-segment start end) (cons start end))(define (start-segment seg) (car seg))(define (end-segment seg) (cdr seg))2.练习2.49(require (planet "sicp.ss" ("soegaard" "sicp原创 2014-01-22 19:12:03 · 633 阅读 · 0 评论 -
练习1.40-练习1.46
1.练习1.40(define (cubic a b c) (define (cube x) (* x x x)) (lambda (x) (+ (cube x) (* a (square x)) (* b x) c)))(define (newtons-method g guess) (fixed-point (ne原创 2014-01-13 21:01:26 · 672 阅读 · 0 评论 -
练习1.35-练习1-38
1.练习1.35(fixed-point (lambda (x) (+ 1 (/ 1 x))) 1.0)2.练习1.36不用平均阻尼方式:(fixed-point-display (lambda (x) (/ (log 1000) (log x))) 2.0)结果为:2.9.9657842846620873.0044722098412146.2791957575071原创 2014-01-11 23:07:30 · 499 阅读 · 0 评论 -
练习1.18-练习1.22
1.练习1.18(define (*-iter a b n) (cond ((= n 0) a) ((even? n) (*-iter a (double b) (halve n))) (else (*-iter (+ a b) b (- n 1)))))(define (* b n) (*-iter 0 b n))Lisp真是强大啊,连 *-iter这种函数名也可以使用!原创 2014-01-08 21:33:03 · 701 阅读 · 0 评论 -
练习1.31-练习1.34
最近对于Lisp的强大和高深还是深有体会的,可以将函数作为参数进行调用,这样在很大的程度上可以提高函数的抽象性,即将具有公共模式的函数进行抽象。例如在SICP中,首先将累加和的过程进行了抽象,然后在累加和的基础上抽象出了累乘积,进而又发现了累加和与累乘积的共同点,进一步抽象成了一个叫做accumulate的函数,这个函数的是这样的(accumulate combiner null-value原创 2014-01-10 19:19:02 · 573 阅读 · 0 评论 -
练习1.23-练习1.30
1.练习1.23改后的代码如下:(define (find-divisor-better n a) (cond ((> (square a) n) n) ((divides?-better n a) a) (else (find-divisor-better n (next-2 a)))))(define (next-2 n) (if (= 2 n) (+原创 2014-01-09 21:05:38 · 508 阅读 · 0 评论 -
练习1.10-练习1.17
1.练习1.10表达式的求值就不说了。(define (f n) (A 0 n)) -------2n(define (g n) (A 1 n))-------2的n次方(define (h n) (A 2 n))-------n个2的次方,例如:(h 4)表示为2的2次方的2次方的2次方2.练习1.11递归计算过程:(define (f1 n) (if (< n原创 2014-01-07 20:47:31 · 623 阅读 · 0 评论 -
练习2.73-练习2.74
1.练习2.73a没有必要b(define (insert-sum-proc) (define (deriv-sum exp var) (make-sum (deriv (car exp) var) (deriv (cadr exp) var))) (put 'deriv '+ deriv-sum) 'done)(define (原创 2014-02-07 17:03:39 · 678 阅读 · 0 评论