12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- (import
- (rename
- (only
- (scheme base)
- define lambda if let +)
- (if scheme-if)
- (+ scheme-+))
- (scheme read)
- (scheme write))
- (define (decode-boolean b)
- ((b #t) #f))
- (define (encode-boolean b)
- (scheme-if b true false))
- (define (decode-number n)
- ((n (lambda (x) (scheme-+ x 1))) 0))
- (define (encode-number n)
- (let loop ((i 0)
- (result zero))
- (scheme-if (< i n)
- (loop (scheme-+ i 1)
- (succ result))
- result)))
- (define false (lambda (a) (lambda (b) b)))
- (define zero (lambda (a) (lambda (b) b)))
- (define null (lambda (a) (lambda (b) b)))
- (define not (lambda (pred) (lambda (a) (lambda (b) ((pred b) a)))))
- (define true (lambda (a) (lambda (b) a)))
- (define succ (lambda (n) (lambda (f) (lambda (x) (f ((n f) x))))))
- (define cons (lambda (a) (lambda (b) (lambda (c) ((c a) b)))))
- (define car (lambda (p) (p true)))
- (define cdr (lambda (p) (p false)))
- (define or (lambda (a) (lambda (b) ((a true) b))))
- (define + (lambda (a) (lambda (b) ((b succ) a))))
- (define zero? (lambda (n) ((n (lambda (x) false)) true)))
- (define null? (lambda (p) ((p (lambda (a) (lambda (b) (lambda (c) false)))) true)))
- (define pred
- (lambda (n)
- (lambda (f)
- (lambda (x)
- (cdr
- ((n (lambda (p)
- ((cons
- false)
- (((car p)
- (cdr p))
- (f (cdr p))))))
- ((cons
- true)
- x)))))))
- (define - (lambda (a) (lambda (b) ((b pred) a))))
|