灯下 登录
计算机科学 / SICP / 2.1.1 Example: Arithmetic Operations for Rational Numbers

Exercise 2.1 · 习题

Exercise 2.1: Define a better version of

make-rat that handles both positive and negative arguments.

Make-rat should normalize the sign so that if the rational number is

positive, both the numerator and denominator are positive, and if the rational

number is negative, only the numerator is negative.

练习 2.1:定义 make-rat 的改进版本,使其能正确处理正数和负数参数。make-rat 应对符号进行规范化:若有理数为正,则分子和分母均为正;若有理数为负,则仅分子为负。