-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.02.scm
41 lines (32 loc) · 911 Bytes
/
2.02.scm
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
40
41
(define (make-point x y)
(cons x y))
(define (x-point point)
(car point))
(define (y-point point)
(cdr point))
(define (make-segment start end)
(cons start end))
(define (start-segment segment)
(car segment))
(define (end-segment segment)
(cdr segment))
(define (midpoint-segment segment)
(define (average a b)
(/ (+ a b) 2))
(let ((start (start-segment segment))
(end (end-segment segment)))
(make-point (average (x-point start)
(x-point end))
(average (y-point start)
(y-point end)))))
(define (print-point p)
(display "(")
(display (x-point p))
(display ", ")
(display (y-point p))
(display ")"))
; test
(define p1 (make-point 1 6))
(define p2 (make-point 3 4))
(define segment (make-segment p1 p2))
(print-point (midpoint-segment segment)) ; (2, 5)