SICP Exercise 3.52
来源:互联网 发布:今年双11淘宝交易额 编辑:程序博客网 时间:2024/05/17 08:56
seq的内容正常应该是(1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210),其中第i个值是由1到i的和而得到的。
> (define sum 0)> sum0> (define (accum x) (set! sum (+ x sum)) sum)> sum0> (define seq (stream-map accum (stream-enumerate-interval 1 20)))> sum1> (define y (stream-filter even? seq))> sum6> (define z (stream-filter (lambda (x) (= (remainder x 5) 0)) seq))> sum10> (stream-ref y 7)136> (display-stream z)10154555105120190210'done> sum210>b)如果delay不使用memo-proc所提过的优化,就会影响上述过程的结果。下面,我们看看delay不使用memo-proc时的情况。
> (define sum 0)> sum0> (define (accum x) (set! sum (+ x sum)) sum)> sum0> (define seq (stream-map accum (stream-enumerate-interval 1 20)))> sum1> (define y (stream-filter even? seq))> sum6> (define z (stream-filter (lambda (x) (= (remainder x 5) 0)) seq))> sum15在执行(define z (stream-filter (lambda (x) (= (remainder x 5) 0)) seq))之前sum的值为6:
- seq的第一个值为1,由于1不是5的倍数,所以取seq的第二个数。
- seq的第二个数需要通过(accum 2)求得,此时sum为6,在执行了(accum 2)之后,sum变为8了。8也不是5的倍数,继续求seq的第3个数。
- seq的第三个数需要通过(accum 3)求的,此时sum为6,在执行了(accum 3)之后,sum变为11。11也不是5的倍数,所以继续。
- seq的第四个数需要通过(accum 4)求的,此时sum为11,在执行了(accum 4)之后,sum变为15。15是5的倍数,所以停止。
- SICP Exercise 3.52
- SICP exercise 1.43
- SICP Exercise 3.11
- SICP Exercise 3.15
- SICP Exercise 3.22
- SICP Exercise 3.25
- SICP Exercise 3.28
- SICP Exercise 3.29
- SICP Exercise 3.33
- SICP Exercise 3.34
- SICP Exercise 3.35
- SICP Exercise 3.37
- SICP Exercise 3.38
- SICP Exercise 3.50
- SICP Exercise 3.51
- SICP Exercise 3.53
- SICP Exercise 3.54
- SICP Exercise 3.55
- Java Observer类
- 80386保护模式编程模型
- 手动进行释放内存的API
- jquery 实现input宽度自适应
- Oracle 高级SQL
- SICP Exercise 3.52
- magento中的joinAttribute joinField
- AJAX 跨域访问 — 方法大全
- 搭建OLAP系统新方法
- 疯狂Android讲义
- filenet小结
- 来源域名。
- 补码的由来
- 有用的linux 命令