乐正

Actions speak louder than words.

Sicp-ex2-7

问题

Alyssa的程序是不完整的,因为她还没有确定区间的抽象实现。这里是区间构造符的定义:

1
(define (make-interval a b) (cons a b))

请定义选择符upper-boundlower-bound,完成这一实现。

解答

1
2
3
(define (upper-bound x) (cdr x))

(define (lower-bound x) (car x))

测试

1
2
3
4
5
(upper-bound (make-interval 100 200))
;Value: 200

(lower-bound (make-interval 100 200))
;Value: 100

draft

« sicp-ex2-6 sicp-ex2-8 »

Comments