(set '0 nil) (set '1+ (lambda (x) (cons t x))) (set '1- (lambda (x) (cdr x))) (set '1 (1+ 0)) (set '2 (1+ 1)) (set '3 (1+ 2)) (set '4 (1+ 3)) (set '5 (1+ 4)) (set '6 (1+ 5)) (set '7 (1+ 6)) (set '8 (1+ 7)) (set '9 (1+ 8)) (set '10 (1+ 9)) (set '& (lambda (x y) (if x (if y t)))) (set '| (lambda (x y) (if x t (if y t)))) (set '! (lambda (x) (if x nil t))) (set 'xor (lambda (x y) (| (& x (! y)) (& (! x) y)))) (set '= (lambda (x y) (if (& x y) (= (1- x) (1- y)) (if (| x y) nil t)))) (set '< (lambda (x y) (if (& x y) (< (1- x) (1- y)) (if (| x y) (if x nil t)) nil))) (set '<= (lambda (x y) (| (= x y) (< x y)))) (set '> (lambda (x y) (! (<= x y)))) (set '>= (lambda (x y) (| (= x y) (> x y)))) (set '+ (lambda (x y) (if y (1+ (+ x (1- y))) x))) (set '- (lambda (x y) (if y (1- (- x (1- y))) x))) (set '* (lambda (x y) (if y (+ (* x (1- y)) x) 0))) (set '% (lambda (x y) (if (> x y) (% (- x y) y) (if (< x y) x 0)))) (set '/ (lambda (x y) (if (< x y) 0 (1+ (/ (- x y) y))))) (set '^ (lambda (x y) (if y (* x (^ x (1- y))) 1))) (set 'log (lambda (x y) (if (>= x y) (1+ (log (/ x y) y)) 0))) (set 'gcd (lambda (x y) (if y (gcd y (% x y)) x))) (set 'fib (lambda (x) (if (< x 2) x (+ (fib (- x 2)) (fib (- x 1)))))) (set 'append (lambda (x y) (if x (if y (cons (car x) (append (cdr x) y)) x) (if y y)))) (set 'reverse (lambda (x) (if x (append (reverse (cdr x)) (cons (car x) nil)) nil))) (set 'length (lambda (x) (if x (1+ (length (cdr x))) 0))) (set 'string->digit (lambda (x) (if (= x 9) '(9) (if (= x 8) '(8) (if (= x 7) '(7) (if (= x 6) '(6) (if (= x 5) '(5) (if (= x 4) '(4) (if (= x 3) '(3) (if (= x 2) '(2) (if (= x 1) '(1) '(0)))))))))))) (set 'digit->string (lambda (x) (if (equal x '9) 9 (if (equal x '8) 8 (if (equal x '7) 7 (if (equal x '6) 6 (if (equal x '5) 5 (if (equal x '4) 4 (if (equal x '3) 3 (if (equal x '2) 2 (if (equal x '1) 1 0))))))))))) (set 'string->list (lambda (x) (if (> x 9) (append (string->list (/ x 10)) (string->digit (% x 10))) (string->digit x)))) (set 'list->string (lambda (x) (if (= (length x) 1) (digit->string (car x)) (+ (digit->string (car (reverse x))) (* 10 (list->string (reverse (cdr (reverse x))))))))) (set 'atom? (lambda (x) (equal x x))) (set 'list? (lambda (x) (if x (! (atom? x)) t))) (string->list (fib (+ 10 5)))