-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.56.rkt
More file actions
36 lines (32 loc) · 1013 Bytes
/
3.56.rkt
File metadata and controls
36 lines (32 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#lang scheme
(require (file "../3.5.1/stream.rkt"))
; pre-define
(define (merge s1 s2)
(cond ((stream-null? s1) s2)
((stream-null? s2) s1)
(else
(let ((s1car (stream-car s1))
(s2car (stream-car s2)))
(cond ((< s1car s2car)
(cons-stream
s1car
(merge (stream-cdr s1) s2)))
((> s1car s2car)
(cons-stream
s2car
(merge s1 (stream-cdr s2))))
(else
(cons-stream
s1car
(merge (stream-cdr s1)
(stream-cdr s2)))))))))
(define (scale-stream stream factor)
(stream-map (lambda (x) (* x factor))
stream))
; require
(define S
(cons-stream 1 (merge (merge (scale-stream S 2)
(scale-stream S 3))
(scale-stream S 5))))
; test
(cond-display-stream S (lambda (x) (< x 50)))