# 练习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-point p)
(car p))

(define (y-point p)
(cdr p))

(define (midpoint-segment seg)
(make-point (/ (+ (x-point (start-segment seg))
(x-point (end-segment seg))) 2)
(/ (+ (y-point (start-segment seg))
(y-point (end-segment seg))) 2)))
2.练习2.3

(define (make-rect start end)
(cons start end))

(define (start-rect seg)
(car seg))

(define (end-rect seg)
(cdr seg))
(define (width rect)
(abs (- (y-point (end-rect rect))
(y-point (start-rect rect)))))

(define (length rect)
(abs (- (x-point (end-rect rect))
(x-point (start-rect rect)))))

(define (girth rect)
(* (+ (width rect)
(length rect))
2))

(define (area rect)
(* (width rect)
(length rect)))

(define (make-rect start length width)
(cons start
(cons length width)))

(define (start-rect seg)
(car seg))

(define (end-rect seg)
(cons (+ (x-point (start-rect seg))
(car (cdr seg)))
(+ (y-point (start-rect seg))
(cdr (cdr seg)))))

3.练习2.4

(define (cons x y)
(lambda (m) (m x y)))

(define (car z)
(z (lambda (p q) p)))

(define (cdr z)
(z (lambda (p q) q)))

4.练习2.5

(define (cons a b)
(* (pow 2 a)
(pow 3 b)))

(define (car c)
(define (iter n result)
(if (not (= (remainder n 2) 0))
result
(iter (/ n 2) (+ result 1))))
(iter c 0))

(define (cdr c)
(define (iter n result)
(if (not (= (remainder n 3) 0))
result
(iter (/ n 3) (+ result 1))))
(iter c 0))

5.练习2.6

(define one
(lambda (f) (lambda (x) (f x))))

(define two
(lambda (f) (lambda (x) (f (f x)))))
(define (add a b)
(lambda (f) (lambda (x) ((b f) ((a f) x)))))
6.练习2.7

(define (make-interval x y)
(cons x y))

(define (upper-bound c)
(cdr c))

(define (lower-bound c)
(car c))
7.练习2.8

(define (sub-interval x y)
(let ((a (- (lower-bound x) (lower-bound y)))
(b (- (upper-bound x) (upper-bound y))))
(make-interval (min a b)
(max a b))))
8.练习2.9

(define (width-interval a)
(/ (- (upper-bound a)
(lower-bound a))
2))
9.练习2.10

(define (div-interval x y)
(if (and (<= (lower-bound y) 0) (>= (upper-bound y) 0))
(error "ERROR!!!")
(mul-interval x
(make-interval (/ 1.0 (upper-bound y))
(/ 1.0 (lower-bound y))))))

08-28 108
07-29 481
10-28 414
03-22 8946
04-18 291
04-20 311
04-18 196
04-18 159
04-18 189
03-08 115
04-19 828
01-29 890
06-28 557
02-18 44
09-30 1588
04-30 23
05-16 382
08-31 460

### “相关推荐”对你有帮助么？

•  非常没帮助
•  没帮助
•  一般
•  有帮助
•  非常有帮助

©️2022 CSDN 皮肤主题：大白 设计师：CSDN官方博客 被折叠的  条评论 为什么被折叠? 到【灌水乐园】发言 _海阔天空

¥2 ¥4 ¥6 ¥10 ¥20  余额支付 (余额：-- )  扫码支付 获取中  扫码支付 点击重新获取   扫码支付 1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。 余额充值