-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudio11.js
36 lines (27 loc) · 992 Bytes
/
studio11.js
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
function scale_stream(c, stream) {
return stream_map(x => c * x, stream);
}
const A = pair(1, () => scale_stream(2, A));
// returns result of (2^x-1 series)
function mul_streams(a,b) {
return pair(head(a) * head(b),
() => mul_streams(stream_tail(a), stream_tail(b)));
}
// const B = pair(1, () => mul_streams(B, integers));
// gives (1*1, 1*2, 2*3, ...
// alt_ones
const ones = pair(1, () => ones);
// when calling as a function, remember to call alt_onesfunc()
// and not just pass alt_ones as a function object
function alt_onesfunc(){
return pair(1,
() => pair(-1,
() => alt_onesfunc()));
}
const alternating_ones = pair(1, () => pair(-1, () => alternating_ones));
const alt_ones = pair(1, () => scale_stream(-1, alt_ones));
function addStreams(s1, s2){
return pair(head(s1) + head(s2),
addStreams(stream_tail(s1), stream_tail(s2)));
}
// addStreams(scale_stream(-1, alternating_ones), alternating_ones);