Add 2.5 and 2.6
This commit is contained in:
parent
4ef752dd47
commit
b8aadcc128
18
2_5.sch
Normal file
18
2_5.sch
Normal 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
13
2_6.sch
Normal 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)))))
|
Loading…
Reference in New Issue
Block a user