Add 2.5 and 2.6

This commit is contained in:
Oliver Payne 2021-05-20 23:02:13 +01:00
parent 4ef752dd47
commit b8aadcc128
2 changed files with 31 additions and 0 deletions

18
2_5.sch Normal file
View File

@ -0,0 +1,18 @@
(define (cons a b)
(* (power 2 a) (power 3 b)))
(define (power x n)
(if (= n 0)
1
(* x (power x (- n 1)))))
(define (iter x n p)
(if (> (remainder x n) 0)
p
(iter (quotient x n) n (+ 1 p))))
(define (car z)
(iter z 2 0))
(define (cdr z)
(iter z 3 0))

13
2_6.sch Normal file
View File

@ -0,0 +1,13 @@
(define zero (lambda (f) (lambda (x) x)))
(define (add-1 n)
(lambda (f) (lambda (x) (f ((n f) x)))))
(define one
(lambda (f) (lambda (x) (f x))))
(define two
(lambda (f) (lambda (x) (f (f x)))))
(define (plus a b)
(lambda (f) (lambda (x) ((a f) ((b f) x)))))