-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.3.scm
More file actions
60 lines (42 loc) · 1.02 KB
/
2.3.scm
File metadata and controls
60 lines (42 loc) · 1.02 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(define (make-point x y)
(cons x y))
(define (x-point p)
(car p))
(define (y-point p)
(cdr p))
(define (print-point p)
(newline)
(display "(")
(display (x-point p))
(display ",")
(display (y-point p))
(display ")"))
(define (make-segment p q)
(cons p q))
(define (start-segment z)
(car z))
(define (end-segment z)
(cdr z))
;(define (make-rect p1 p2)
; (cons p1 p2))
;(define (rect-xlen r)
; (abs (- (x-point (car r)) (x-point (cdr r)))))
;(define (rect-ylen r)
; (abs (- (y-point (car r)) (y-point (cdr r)))))
(define (make-rect p w h)
(cons p (cons w h)))
(define (rect-xlen r)
(car (cdr r)))
(define (rect-ylen r)
(cdr (cdr r)))
(define (rect-perimeter r)
(* 2 (+ (rect-xlen r) (rect-ylen r))))
(define (rect-area r)
(* (rect-xlen r) (rect-ylen r)))
;(define myrect (make-rect (make-point 0 0)
; (make-point 4 5)))
(define myrect (make-rect (make-point 0 0)
4
5))
(rect-perimeter myrect)
(rect-area myrect)