Last active
December 30, 2015 16:49
-
-
Save johnelf/7857281 to your computer and use it in GitHub Desktop.
SICP练习
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5)))) (* 3 (- 6 2) (- 2 7)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (sum-of-two x y z) (if (> x y) | |
(if (> y z) | |
(+ x y) | |
(+ x z)) | |
(if (> x z) | |
(+ x y) | |
(+ z y))) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (p) (p)) | |
(define (test x y) | |
(if (= x 0) | |
0 | |
y)) | |
(test 0 (p)) | |
如果是正则序则直接进行参数替换,Ben会看到0; | |
如果是应用序则会先求参数的值,Ben会看到屏幕卡死(死循环)。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (abs x) | |
(if (> x 0) | |
x | |
(- x))) | |
(define (average x y) | |
(/ (+ x y) 2)) | |
(define (improve guess x) | |
(average guess (/ x guess))) | |
(define (good-enough? guess x) | |
(< (abs (- (square guess) x)) 0.001)) | |
(define (sqrt-iter guess x) | |
(if (good-enough? guess x) | |
guess | |
(sqrt-iter (improve guess x) | |
x))) | |
(define (sqrt x) | |
(sqrt-iter 1.0 x)) | |
(sqrt 0.00002) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (abs x) | |
(if (> x 0) | |
x | |
(- x))) | |
(define (average x y) | |
(/ (+ x y) 2)) | |
(define (improve guess x) | |
(average guess (/ x guess))) | |
(define (good-enough? guess x) | |
(< (abs (- (square guess) x)) 0.001)) | |
(define (sqrt-iter guess x) | |
(if (good-enough? guess x) | |
guess | |
(sqrt-iter (improve guess x) | |
x))) | |
(define (sqrt x) | |
(sqrt-iter 1.0 x)) | |
(sqrt 9999999999999999999999999) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (abs x) | |
(if (> x 0) | |
x | |
(- x))) | |
(define (average x y) | |
(/ (+ x y) 2)) | |
(define (improve guess x) | |
(average guess (/ x guess))) | |
(define (good-enough? guess x) | |
(< (/ (abs (- (square guess) x)) guess) 0.000001)) | |
(define (sqrt-iter guess x) | |
(if (good-enough? guess x) | |
guess | |
(sqrt-iter (improve guess x) | |
x))) | |
(define (sqrt x) | |
(sqrt-iter 1.0 x)) | |
(sqrt 9999999999999999999999999) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment