乐正

Actions speak louder than words.

Sicp-ex2-48

问题

平面上的一条直线段可以用一对向量表示——从原点到线段起点的向量,以及从原点到线段终 点的向量。请用你在练习2.46做出的向量表示定义一种线段表示,其中用构造函数make-segment 以及选择函数start-segmentend-segment

解答

练习2.48 (ex2-48.scm) download
1
2
3
4
5
6
7
8
9
(define (make-segment vect1 vect2)
  (cons (ycor-vect vect1)
        (ycor-vect vect2)))

(define (start-segment segment)
  (car segment))

(define (end-segment segment)
  (cdr segment))

测试

1
2
3
4
5
6
7
8
9
(define seg (make-segment (make-vect 3 4)
                          (make-vect 10 18)))
;Value: seg

(start-segment seg)
;Value: 4

(end-segment seg)
;Value: 18

draft

« sicp-ex2-47 sicp-ex2-49 »

Comments