summaryrefslogtreecommitdiff
path: root/coding-exercises/2/83
diff options
context:
space:
mode:
Diffstat (limited to 'coding-exercises/2/83')
-rw-r--r--coding-exercises/2/83/install-rational.rkt3
-rw-r--r--coding-exercises/2/83/install-real.rkt1
-rw-r--r--coding-exercises/2/83/install.rkt2
3 files changed, 6 insertions, 0 deletions
diff --git a/coding-exercises/2/83/install-rational.rkt b/coding-exercises/2/83/install-rational.rkt
index 73640b7..337f38b 100644
--- a/coding-exercises/2/83/install-rational.rkt
+++ b/coding-exercises/2/83/install-rational.rkt
@@ -11,6 +11,9 @@
(make-rat (+ (* (numer x) (denom y))
(* (numer y) (denom x)))
(* (denom x) (denom y))))
+ (define (neg-rat rat)
+ (make-rat (- (numer rat))
+ (denom rat)))
(define (sub-rat x y)
(make-rat (- (* (numer x) (denom y))
(* (numer y) (denom x)))
diff --git a/coding-exercises/2/83/install-real.rkt b/coding-exercises/2/83/install-real.rkt
index 68f5e31..6b96137 100644
--- a/coding-exercises/2/83/install-real.rkt
+++ b/coding-exercises/2/83/install-real.rkt
@@ -14,6 +14,7 @@
(put 'make 'real (lambda (x) (tagme (make x))))
;; methods
(put 'add '(real real) (lambda (x y) (tagme (make (+ x y)))))
+ (put 'neg '(real) (lambda (x) (tagme (make (- x)))))
(put 'sub '(real real) (lambda (x y) (tagme (make (- x y)))))
(put 'mul '(real real) (lambda (x y) (tagme (make (* x y)))))
(put 'div '(real real) (lambda (x y) (tagme (make (/ x y)))))
diff --git a/coding-exercises/2/83/install.rkt b/coding-exercises/2/83/install.rkt
index 0cd8bbf..d972784 100644
--- a/coding-exercises/2/83/install.rkt
+++ b/coding-exercises/2/83/install.rkt
@@ -86,6 +86,8 @@
(apply-fn '=zero? datum))
(define (add a1 a2)
(apply-fn 'add a1 a2))
+(define (neg a)
+ (apply-fn 'neg a))
(define (sub a1 a2)
(apply-fn 'sub a1 a2))
(define (mul a1 a2)