(define (linear-combination a b x y) (add (mul a x) (mul b y)))
(define (rat+ x y) (make-rat (+ (* (numer x) (denom y)) (* (denom x) (numer y))) (* (denom x) (denom y)))) (define (rat- x y) (make-rat (- (* (numer x) (denom y)) (* (denom x) (numer y))) (* (denom x) (denom y)))) (define (rat* x y) (make-rat (* (numer x) (numer y)) (* (denom x) (denom y)))) (define (rat/ x y) (make-rat (* (numer x) (denom y)) (* (denom x) (numer y)))) (define (rat=? x y) (= (* (numer x) (denom y)) (* (denom x) (numer y)))) (define (print-rat x) (newline) (display (numer x)) (display "/") (display (denom x)) #T)
(define (make-rat n d) (cons n d)) (define (numer x) (car x)) (define (denom x) (cdr x))
(define (make-rat n d) (let ((g (gcd n d))) (cons (/ n g) (/ d g))))
(define (cons x y) (define (dispatch m) (cond ((= m 0) x) ((= m 1) y) (else (error "Wrong message!")))) dispatch) (define (car z) (z 0)) (define (cdr z) (z 1))
(define (cons x y) (lambda (m) (m x y))) (define (car z) (z (lambda (p q) p))) (define (cdr z) (z (lambda (p q) q)))
(define (nth n zoz) (cond ((null? zoz) ()) ((= n 0) (car zoz)) (else (nth (1- n) (cdr zoz))))) (define (length zoz) (if (null? zoz) 0 (1+ (length (cdr zoz)))))
(define (countatoms x) (cond ((null? x) 0) ((atom? x) 1) (else (+ (countatoms (car x)) (countatoms (cdr x))))))