-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.2.rkt
39 lines (39 loc) · 955 Bytes
/
2.2.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#lang planet neil/sicp
;;点
(define(make-point n d)
(cons n d))
(define(x-point point)
(car point))
(define(y-point point)
(cdr point))
;;线段
(define(make-segment start-point end-point)
(cons start-point end-point))
(define (start-segment seg)
(car seg))
(define (end-segment seg)
(cdr seg))
;;中点
(define (midpoint-segment seg)
(let((start(start-segment seg))
(end(end-segment seg)))
(make-point(average(x-point start)
(x-point end))
(average(y-point start)
(y-point end)))))
(define(average x y)
(/(+ x y)2))
;;打印
(define (print-point p)
(newline)
(display "(")
(display (x-point p))
(display ",")
(display (y-point p))
(display ")"))
;;点(1,3)(4,3)的中点
(define start (make-point 1.0 3.0))
(define end (make-point 4.0 3.0))
(define seg (make-segment start end))
(define mid (midpoint-segment seg))
(print-point mid)