Scheme] 
(define (make-rat n d) (cons n d))

make-rat

Scheme] 
(define (numer x) (car x))

numer

Scheme] 
(define (denom x) (cdr x))

denom

Scheme] 
(define (分式 n d) (make-rat n d))

分式

Scheme] 
(define (分子 x) (numer x))

分子

Scheme] 
(define (分母 x) (denom x))

分母

Scheme] 
(kbd-map ("f z var" (insert (utf8->cork "分子"))))

("f z tab")

Scheme] 
(kbd-map ("f s var" (insert (utf8->cork "分式"))))

("f s tab")

Scheme] 
(kbd-map ("f m var" (insert (utf8->cork "分母"))))

("f m tab")

Scheme]
Scheme] 
(define (add-rat x y)
  (make-rat (+ (* (numer x) (denom y))
               (* (numer y) (denom x)))
            (* (denom x) (denom y))))

add-rat

Scheme] 
(define (sub-rat x y)
  (make-rat (- (* (numer x) (denom y))
               (* (numer y) (denom x)))
            (* (denom x) (denom y))))

sub-rat

Scheme] 
(define (mul-rat x y)
  (make-rat (* (numer x) (numer y))
            (* (denom x) (denom y))))

mul-rat

Scheme] 
(define (div-rat x y)
  (make-rat (* (numer x) (denom y))
            (* (denom x) (numer y))))

div-rat

Scheme] 
(define (equal-rat? x y)
  (= (* (numer x) (denom y))
     (* (numer y) (denom x))))

equal-rat?

Scheme] 
(kbd-map ("f s + var" (insert (utf8->cork "分式加"))))

("f s + tab")

Scheme] 
(kbd-map ("f s - var" (insert (utf8->cork "分式减"))))

("f s - tab")

Scheme] 
(kbd-map ("f s * var" (insert (utf8->cork "分式乘"))))

("f s * tab")

Scheme] 
(kbd-map ("f s / var" (insert (utf8->cork "分式除"))))

("f s / tab")

Scheme] 
(kbd-map ("f s x var" (insert (utf8->cork "分式显"))))

("f s x tab")

Scheme] 
(define (分式加 x y) (add-rat x y))

分式加

Scheme] 
(define (分式减 x y) (sub-rat x y))

分式减

Scheme] 
(define (分式乘 x y) (mul-rat x y))

分式乘

Scheme] 
(define (分式除 x y) (div-rat x y))

分式除

Scheme]
Scheme] 
(define x (cons 1 2))

(1 . 2)

Scheme] 
(car x)

1

Scheme] 
(cdr x)

2

Scheme]
Scheme] 
(define x (cons 1 2))

(1 . 2)

Scheme] 
(define y (cons 3 4))

(3 . 4)

Scheme] 
(define z (cons x y))

((1 . 2) 3 . 4)

Scheme] 
(car (car z))

1

Scheme]

Scheme]
(define (print-rat x)
  (newline)
  (display (numer x))
  (display "/")
  (display (denom x)))
Scheme] 
(define (分式显 x)
  (stree->tree ‘(frac ,(分子 x) ,(分母 x))))

分式显

Scheme]
Scheme] 
(define 二分之一 (分式 1 2))

(1 . 2)

Scheme] 
(define 三分之一 (分式 1 3))

(1 . 3)

Scheme] 
(分式显 三分之一)

1
3

Scheme] 
(分式显 二分之一)

1
2

Scheme] 
(分式显 (分式加 二分之一 三分之一))
Scheme] 
(分式显 (分式减 二分之一 三分之一))

1
6

Scheme] 
(分式显 (分式乘 二分之一 三分之一))

1
6

Scheme] 
(分式显 (分式除 二分之一 三分之一))

3
2

Scheme]
Scheme] 
(define (make-rat n d)
  (let ((g (gcd n d)))
    (cons (/ n g) (/ d g))))
Scheme]
(print-rat (add-rat one-third one-third))
Scheme]