; COSC 152 ; Fall 2006 ; 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 (m n) (if (is-zero? m) n (add (pred m) (succ n)) ))) ; 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) '() (succ (translate (- x 1)))))) (define untranslate (lambda (x) (if (is-zero? x) 0 (+ 1 (untranslate (pred x))))))