Created
March 22, 2015 01:42
-
-
Save kouddy/ff78de478c01f65aabb4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; Assume n and d are never 0, else gcd will return 0, which causes division by zero | |
(define (make-rat n d) | |
(define g (gcd n d)) | |
(if (or (and (< n 0) (< d 0)) (and (> n 0) (> d 0))) | |
(cons (/ (abs n) g) (/ (abs d) g)) | |
(cons (/ n g) (/ d g)))) | |
(define (numer x) (car x)) | |
(define (denom x) (cdr x)) | |
(define (print-rat x) | |
(display (numer x)) | |
(display "/") | |
(display (denom x))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment