# 练习1.1－练习1.9

16 篇文章 0 订阅
15 篇文章 0 订阅

1. 练习1.1

2. 练习1.2

(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5)))))
(* 3 (- 6 2) (- 2 7)))


3.练习1.3

(define (sumofmax2 x y z)
(- (+ x y z)
(cond ((and (< x y) (< x z)) x)
((and (< y x) (< y z)) y)
(else z))))

4.练习1.4

5.练习1.5

Scheme的解释器用的是应用序，所以在求表达式(test 0 (p))时首先会将(p)进行展开，可以看到p的实现时他自己，所以会进入一个无穷的递归，最终导致“死机”或者奔溃。

(if (= 0 0)
0
(p))

6.练习1.6

7.练习1.7

(define (good-enough? guess old-guess)
(and (> (/ guess old-guess) 0.99999999999999)
(< (/ guess old-guess) 1.00000000000001)))

(define (average x y)
(/ (+ x y) 2))

(define (improve guess x)
(average guess (/ x guess)))

(define (sqrt-iter guess old-guess x)
(if (good-enough? guess old-guess)
guess
(sqrt-iter (improve guess x) guess x)))

(define (sqrt x)
(sqrt-iter 1.0 0.1 x))

8.练习1.8

(define (good-enough? guess old-guess)
(and (> (/ guess old-guess) 0.9999)
(< (/ guess old-guess) 1.0001)))

(define (improve guess x)
(/ (+ (/ x (* guess guess)) (* 2 guess)) 3))

(define (cbrt-iter guess old-guess x)
(if (good-enough? guess old-guess)
guess
(cbrt-iter (improve guess x) guess x)))

(define (cbrt x)
(cbrt-iter 1.0 0.1 x))

9.练习1.9

• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 0
评论
01-08 664
01-13 626
02-07 617
01-20 617
01-20 591
01-07 590
01-22 584
01-20 573
01-17 566
01-23 562
01-15 559
01-10 533
01-14 491

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。