sicp-solutions/ex-2.01.scm
Petar Kapriš 1b2b2dfec1 Add solutions to exercises from section 2.1
To be noted: the last two exercises, 2.15 and 2.16 were left unfinished,
and will be left for another time.
2025-02-05 15:17:47 +01:00

8 lines
231 B
Scheme

#lang sicp
(define (make-rat n d)
(let ((g (gcd n d)))
(cond ((= d 0)
(error "Cannot make-rat with denominator 0"))
((< d 0) (cons (- (/ n g)) (- (/ d g))))
(else (cons (/ n g) (/ d g))))))