> <\body> <\session|scheme|default> <\unfolded-io|Scheme] > (define (make-rat n d) (cons n d)) <|unfolded-io> make-rat <\unfolded-io|Scheme] > (define (numer x) (car x)) <|unfolded-io> numer <\unfolded-io|Scheme] > (define (denom x) (cdr x)) <|unfolded-io> denom <\unfolded-io|Scheme] > (define (\<#5206\>\<#5F0F\> n d) (make-rat n d)) <|unfolded-io> \<#5206\>\<#5F0F\> <\unfolded-io|Scheme] > (define (\<#5206\>\<#5B50\> x) (numer x)) <|unfolded-io> \<#5206\>\<#5B50\> <\unfolded-io|Scheme] > (define (\<#5206\>\<#6BCD\> x) (denom x)) <|unfolded-io> \<#5206\>\<#6BCD\> <\unfolded-io|Scheme] > (kbd-map ("f z var" (insert (utf8-\cork "\<#5206\>\<#5B50\>")))) <|unfolded-io> ("f z tab") <\unfolded-io|Scheme] > (kbd-map ("f s var" (insert (utf8-\cork "\<#5206\>\<#5F0F\>")))) <|unfolded-io> ("f s tab") <\unfolded-io|Scheme] > (kbd-map ("f m var" (insert (utf8-\cork "\<#5206\>\<#6BCD\>")))) <|unfolded-io> ("f m tab") <\input|Scheme] > \; <\session|scheme|default> <\unfolded-io|Scheme] > <\with|prog-scripts|scheme> (define (add-rat x y) \ \ (make-rat (+ (* (numer x) (denom y)) \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (* (numer y) (denom x))) \ \ \ \ \ \ \ \ \ \ \ \ (* (denom x) (denom y)))) <|unfolded-io> add-rat <\unfolded-io|Scheme] > (define (sub-rat x y) \ \ (make-rat (- (* (numer x) (denom y)) \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (* (numer y) (denom x))) \ \ \ \ \ \ \ \ \ \ \ \ (* (denom x) (denom y)))) <|unfolded-io> sub-rat <\unfolded-io|Scheme] > (define (mul-rat x y) \ \ (make-rat (* (numer x) (numer y)) \ \ \ \ \ \ \ \ \ \ \ \ (* (denom x) (denom y)))) <|unfolded-io> mul-rat <\unfolded-io|Scheme] > (define (div-rat x y) \ \ (make-rat (* (numer x) (denom y)) \ \ \ \ \ \ \ \ \ \ \ \ (* (denom x) (numer y)))) <|unfolded-io> div-rat <\unfolded-io|Scheme] > (define (equal-rat? x y) \ \ (= (* (numer x) (denom y)) \ \ \ \ \ (* (numer y) (denom x)))) <|unfolded-io> equal-rat? <\unfolded-io|Scheme] > (kbd-map ("f s + var" (insert (utf8-\cork "\<#5206\>\<#5F0F\>\<#52A0\>")))) <|unfolded-io> ("f s + tab") <\unfolded-io|Scheme] > (kbd-map ("f s - var" (insert (utf8-\cork "\<#5206\>\<#5F0F\>\<#51CF\>")))) <|unfolded-io> ("f s - tab") <\unfolded-io|Scheme] > (kbd-map ("f s * var" (insert (utf8-\cork "\<#5206\>\<#5F0F\>\<#4E58\>")))) <|unfolded-io> ("f s * tab") <\unfolded-io|Scheme] > (kbd-map ("f s / var" (insert (utf8-\cork "\<#5206\>\<#5F0F\>\<#9664\>")))) <|unfolded-io> ("f s / tab") <\unfolded-io|Scheme] > (kbd-map ("f s x var" (insert (utf8-\cork "\<#5206\>\<#5F0F\>\<#663E\>")))) <|unfolded-io> ("f s x tab") <\unfolded-io|Scheme] > (define (\<#5206\>\<#5F0F\>\<#52A0\> x y) (add-rat x y)) <|unfolded-io> \<#5206\>\<#5F0F\>\<#52A0\> <\unfolded-io|Scheme] > (define (\<#5206\>\<#5F0F\>\<#51CF\> x y) (sub-rat x y)) <|unfolded-io> \<#5206\>\<#5F0F\>\<#51CF\> <\unfolded-io|Scheme] > (define (\<#5206\>\<#5F0F\>\<#4E58\> x y) (mul-rat x y)) <|unfolded-io> \<#5206\>\<#5F0F\>\<#4E58\> <\unfolded-io|Scheme] > (define (\<#5206\>\<#5F0F\>\<#9664\> x y) (div-rat x y)) <|unfolded-io> \<#5206\>\<#5F0F\>\<#9664\> <\input|Scheme] > \; <\session|scheme|default> <\unfolded-io|Scheme] > (define x (cons 1 2)) <|unfolded-io> (1 . 2) <\unfolded-io|Scheme] > (car x) <|unfolded-io> 1 <\unfolded-io|Scheme] > (cdr x) <|unfolded-io> 2 <\input|Scheme] > \; <\session|scheme|default> <\unfolded-io|Scheme] > (define x (cons 1 2)) <|unfolded-io> (1 . 2) <\unfolded-io|Scheme] > (define y (cons 3 4)) <|unfolded-io> (3 . 4) <\unfolded-io|Scheme] > (define z (cons x y)) <|unfolded-io> ((1 . 2) 3 . 4) <\unfolded-io|Scheme] > (car (car z)) <|unfolded-io> 1 <\input|Scheme] > \; \; <\session|scheme|default> <\input|Scheme] > (define (print-rat x) \ \ (newline) \ \ (display (numer x)) \ \ (display "/") \ \ (display (denom x))) <\unfolded-io|Scheme] > (define (\<#5206\>\<#5F0F\>\<#663E\> x) \ \ (stree-\tree `(frac ,(\<#5206\>\<#5B50\> x) ,(\<#5206\>\<#6BCD\> x)))) <|unfolded-io> \<#5206\>\<#5F0F\>\<#663E\> <\input|Scheme] > \; <\session|scheme|default> <\unfolded-io|Scheme] > (define \<#4E8C\>\<#5206\>\<#4E4B\>\<#4E00\> (\<#5206\>\<#5F0F\> 1 2)) <|unfolded-io> (1 . 2) <\unfolded-io|Scheme] > (define \<#4E09\>\<#5206\>\<#4E4B\>\<#4E00\> (\<#5206\>\<#5F0F\> 1 3)) <|unfolded-io> (1 . 3) <\unfolded-io|Scheme] > (\<#5206\>\<#5F0F\>\<#663E\> \<#4E09\>\<#5206\>\<#4E4B\>\<#4E00\>) <|unfolded-io> > <\unfolded-io|Scheme] > (\<#5206\>\<#5F0F\>\<#663E\> \<#4E8C\>\<#5206\>\<#4E4B\>\<#4E00\>) <|unfolded-io> > <\folded-io|Scheme] > (\<#5206\>\<#5F0F\>\<#663E\> (\<#5206\>\<#5F0F\>\<#52A0\> \<#4E8C\>\<#5206\>\<#4E4B\>\<#4E00\> \<#4E09\>\<#5206\>\<#4E4B\>\<#4E00\>)) <|folded-io> > <\unfolded-io|Scheme] > (\<#5206\>\<#5F0F\>\<#663E\> (\<#5206\>\<#5F0F\>\<#51CF\> \<#4E8C\>\<#5206\>\<#4E4B\>\<#4E00\> \<#4E09\>\<#5206\>\<#4E4B\>\<#4E00\>)) <|unfolded-io> > <\unfolded-io|Scheme] > (\<#5206\>\<#5F0F\>\<#663E\> (\<#5206\>\<#5F0F\>\<#4E58\> \<#4E8C\>\<#5206\>\<#4E4B\>\<#4E00\> \<#4E09\>\<#5206\>\<#4E4B\>\<#4E00\>)) <|unfolded-io> > <\unfolded-io|Scheme] > (\<#5206\>\<#5F0F\>\<#663E\> (\<#5206\>\<#5F0F\>\<#9664\> \<#4E8C\>\<#5206\>\<#4E4B\>\<#4E00\> \<#4E09\>\<#5206\>\<#4E4B\>\<#4E00\>)) <|unfolded-io> > <\input|Scheme] > \; <\session|scheme|default> <\input> Scheme]\ <|input> (define (make-rat n d) \ \ (let ((g (gcd n d))) \ \ \ \ (cons (/ n g) (/ d g)))) <\session|scheme|default> <\input|Scheme] > (print-rat (add-rat one-third one-third)) <\input|Scheme] > \; <\initial> <\collection> <\references> <\collection> > > > <\auxiliary> <\collection> <\associate|toc> |2.1.1 |.>>>>|> > |2.1.2 |.>>>>|> > |2.1.3 |.>>>>|> >