Solution to SICP Exercise 2.1

Structure and Interpretation of Computer Programs

Solution to Exercise 2.1:

(define (make-rat n d)
(let ((new-n (if (negative? d) (- n) n))
(new-d (abs d)))
(let ((g (gcd new-n new-d)))
(cons (/ new-n g) (/ new-d g)))))

Advertisements