Skip to content

Commit 65d6ac3

Browse files
committed
Add implementation of exercise 3-55
1 parent a5d9a4e commit 65d6ac3

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

README.org

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
习题完成情况:
2626
- 章节一: 43/46
2727
- 章节二: 88/97
28-
- 章节三: 54/82
28+
- 章节三: 55/82
2929
- 章节四: TODO
3030
- 章节五: TODO
3131
* 运行

chapter3/exercise3-54.rkt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
(require "exercise3-50.rkt")
44
(require "infinite-stream.rkt")
55

6-
(define (mul-stream s1 s2)
6+
(define (mul-streams s1 s2)
77
(map-stream * s1 s2))
88

9-
(define factorials (cons-stream 1 (mul-stream (stream-cdr integers) factorials)))
9+
(define factorials (cons-stream 1 (mul-streams (stream-cdr integers) factorials)))
1010

1111
(module+ test
1212
(require rackunit)
1313

1414
(test-case "Test for mul-stream"
1515
(define s1 (list-to-stream '(2 3 4 5)))
1616
(define s2 (list-to-stream '(3 4 5 6)))
17-
(define s3 (mul-stream s1 s2))
17+
(define s3 (mul-streams s1 s2))
1818
(check-equal? (stream-ref s3 2) 20)
1919
(check-equal? (stream-to-list s3 4) '(6 12 20 30))
2020
)

chapter3/exercise3-55.rkt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#lang racket
2+
(require "stream.rkt")
3+
(require "infinite-stream.rkt")
4+
5+
(define (partial-sums s1)
6+
(cons-stream (stream-car s1) (add-streams (partial-sums s1) (stream-cdr s1)))
7+
)
8+
9+
(module+ test
10+
(require rackunit)
11+
12+
(test-case "Test for partial-sums"
13+
(define s1 (partial-sums integers))
14+
(check-equal? (stream-to-list s1 5) '(1 3 6 10 15))
15+
)
16+
)

0 commit comments

Comments
 (0)