Scheme] |
(define (make-rat n d) (cons n d)) |
Scheme] |
(define (numer x) (car x)) |
Scheme] |
(define (denom x) (cdr x)) |
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 "分子")))) |
Scheme] |
(kbd-map ("f s var" (insert (utf8->cork "分式")))) |
Scheme] |
(kbd-map ("f m var" (insert (utf8->cork "分母")))) |
Scheme] |
Scheme] |
(define (add-rat x y) (make-rat (+ (* (numer x) (denom y)) (* (numer y) (denom x))) (* (denom x) (denom y)))) |
Scheme] |
(define (sub-rat x y) (make-rat (- (* (numer x) (denom y)) (* (numer y) (denom x))) (* (denom x) (denom y)))) |
Scheme] |
(define (mul-rat x y) (make-rat (* (numer x) (numer y)) (* (denom x) (denom y)))) |
Scheme] |
(define (div-rat x y) (make-rat (* (numer x) (denom y)) (* (denom x) (numer y)))) |
Scheme] |
(define (equal-rat? x y) (= (* (numer x) (denom y)) (* (numer y) (denom x)))) |
Scheme] |
(kbd-map ("f s + var" (insert (utf8->cork "分式加")))) |
Scheme] |
(kbd-map ("f s - var" (insert (utf8->cork "分式减")))) |
Scheme] |
(kbd-map ("f s * var" (insert (utf8->cork "分式乘")))) |
Scheme] |
(kbd-map ("f s / var" (insert (utf8->cork "分式除")))) |
Scheme] |
(kbd-map ("f s x var" (insert (utf8->cork "分式显")))) |
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)) |
Scheme] |
(car x) |
Scheme] |
(cdr x) |
Scheme] |
Scheme] |
(define x (cons 1 2)) |
Scheme] |
(define y (cons 3 4)) |
Scheme] |
(define z (cons x y)) |
Scheme] |
(car (car z)) |
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)) |
Scheme] |
(define 三分之一 (分式 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] |