diff options
| author | Steve Lee <me@xiangyangli.com> | 2016-10-12 09:05:07 +0800 |
|---|---|---|
| committer | Steve Lee <me@xiangyangli.com> | 2016-10-12 09:05:07 +0800 |
| commit | a335f1cefb6838cf85fcdc6f58a4a87899dfb981 (patch) | |
| tree | eda239a6282f895d436016bd868bade7b34e3b74 | |
| parent | 3247365f03b803733033c0632a625d25fd307b59 (diff) | |
| download | Personal-a335f1cefb6838cf85fcdc6f58a4a87899dfb981.tar.xz Personal-a335f1cefb6838cf85fcdc6f58a4a87899dfb981.zip | |
add ex-2.4 - ex-2.5
| -rw-r--r-- | SICP/ex2-4.scm | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/SICP/ex2-4.scm b/SICP/ex2-4.scm index bfc3b64..9078d99 100644 --- a/SICP/ex2-4.scm +++ b/SICP/ex2-4.scm @@ -53,5 +53,24 @@ (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 three (lambda(f) (lambda (x) (f (f (f x)))))) -(= one (add-1 zero)) +(define (add a b) + (lambda (f) + (lambda (x) + ((a f) ((b f) x))))) + +;; Excellent answer for add a b, actually it's the +;; same compared with above imp. +(define (add a b) + ((a add-1) b)) + +(zero 1) + +(define (square x) (* x x)) + +((two square) 2) +((three square) 2) + +(((add two one) square) 2) |
