-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.scm
45 lines (32 loc) · 998 Bytes
/
test.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
42
43
44
45
(define (make-rat n d)
(cond ((and (< n 0) (< d 0)) (cons (- n ) (- d)))
((< d 0) (cons (if (< n 0) (+ n) n) d))
((and (> n 0) (> d 0)) (cons n d))))
(define (numer x)
(car x))
(define (denom x)
(cdr x))
;(define (add-rat x y)
; (make-rat (+ (* (numer x) (denom y))
; (* (numer y) (denom x)))
; (* (denom x) (denom y))))
;(define (sub-rat x y)
; (make-rat (+ (* (numer x) (denom y))
; (* (numer y) (denom x)))
; (* (denom x) (denom y))))
;(define (mul-rat x y)
; (make-rat (* (numer x) (numer y)) (* (denom x) (denom y))))
;(define (div-rat x y)
; (make-rat (* (numer x) (denom y)) (* (numer y) (denom x))))
(define (print-rat x)
(newline)
(display (numer x))
(display "/")
(display (denom x)))
(define testing (make-rat (- 1) (- 2)))
(print-rat testing)
(define testing (make-rat 1 (- 2)))
(print-rat testing)
;(define test (make-rat 1 3))
;(print-rat test)
;(print-rat ( add-rat testing test))