Skip to content

Instantly share code, notes, and snippets.

@ecounysis
Created February 25, 2012 05:10
Show Gist options
  • Save ecounysis/1906580 to your computer and use it in GitHub Desktop.
Save ecounysis/1906580 to your computer and use it in GitHub Desktop.
Numbers from "The Little Schemer"
(define (add1 x) (+ x 1))
(define (sub1 x) (- x 1))
(define (o+ x y)
(cond ((= y 0) x)
(else (o+ (add1 x) (sub1 y)))))
(define (o- x y)
(cond ((= y 0) x)
(else (o- (sub1 x) (sub1 y)))))
(define (o* x y)
(cond ((= 0 y) 0)
((= 1 y) x)
(else (o+ x (o* x (sub1 y))))))
(define (o/ x y)
(cond ((= 0 y) null)
((= 1 y) x)
((< x y) 0)
(else (add1 (o/ (o- x y) y)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment