Advertisement
timothy235

sicp-2-1-1-rational-number-arithmetic

Feb 18th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.22 KB | None | 0 0
  1. #lang racket
  2.  
  3. ;;;;;;;;;
  4. ;; 2.1 ;;
  5. ;;;;;;;;;
  6.  
  7. (define (make-rat n d)
  8.   (cond [(negative? d) (make-rat (- n) (- d))]
  9.         [else
  10.           (define g (gcd n d)) ; gcd always > 0
  11.           (cons (/ n g) (/ d g))]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement