练习 2.1

根据有理数的负数处理规则:

\(\frac{-n}{-d} = \frac{n}{d}\)

\(\frac{n}{-d} = \frac{-n}{d}\)

可以给出题目要求的能处理负数的 make-rat

;;; 1-make-rat.scm

(define (make-rat n d)
    (if (< d 0)
        (cons (- n) (- d))
        (cons n d)))

讨论

blog comments powered by Disqus