; COSC 152 ; Fall 2005 ; Dennis Brylow ; ; Lecture 4 Demo ; Implementing a number system without numbers. (define is-zero? (lambda (x) (null? x))) (define succ (lambda (x) (cons '() x))) (define pred (lambda (x) (if (is-zero? x) x (cdr x) ))) (define add (lambda (x y) (if (is-zero? x) y (add (pred x) (succ y)) ))) ; See The Little Schemer for more functions like ; subtraction, multiplication, division, exponentiation, etc. ; And now some functions to translate back and forth between ; the native Scheme representation of numbers and my new ; list-based representation of numbers. (define translate (lambda (x) (if (zero? x) '() (cons '() (translate (- x 1)))))) (define untranslate (lambda (x) (if (is-zero? x) 0 (+ 1 (untranslate (cdr x))))))