@@ -15,16 +15,16 @@ export
1515#  Infinite counting
1616
1717type Count
18- 
18+     start :: Any 
1919    step:: Any 
2020end 
2121
22- count (start, step)            =  Count (start, step)
23- count {T <: Number} (start:: T )  =  Count (start, convert (T,  1 ))
24- count ()                       =  Count (0 , 1 )
22+ count (start, step) =  Count (start, step)
23+ count (start)        =  Count (start, one (start ))
24+ count ()            =  Count (0 , 1 )
2525
2626start (it:: Count ) =  it. start
27- next (it:: Count , state) =  (state, state +  1 )
27+ next (it:: Count , state) =  (state, state +  it . step )
2828done (it:: Count , state) =  false 
2929
3030
@@ -40,13 +40,13 @@ take(xs, n) = Take(xs, n)
4040start (it:: Take ) =  (it. n, start (it. xs))
4141
4242function  next (it:: Take , state)
43-     ( n, xs_state)  =  state
44-     ( v, xs_state)  =  next (it. xs, xs_state)
45-     ( v, (n -  1 , xs_state) )
43+     n, xs_state =  state
44+     v, xs_state =  next (it. xs, xs_state)
45+     return   v, (n -  1 , xs_state)
4646end 
4747
4848function  done (it:: Take , state)
49-     ( n, xs_state)  =  state
49+     n, xs_state =  state
5050    return  n <=  0  ||  done (it. xs, xs_state)
5151end 
5252
@@ -67,7 +67,7 @@ function start(it::Drop)
6767            break 
6868        end 
6969
70-         ( _, xs_state)  =  next (it. xs, xs_state)
70+         _, xs_state =  next (it. xs, xs_state)
7171    end 
7272    xs_state
7373end 
8484
8585cycle (xs) =  Cycle (xs)
8686
87- start (it:: Cycle ) =  start (it. xs)
87+ function  start (it:: Cycle )
88+     s =  start (it. xs)
89+     return  s, done (it. xs, s)
90+ end 
8891
8992function  next (it:: Cycle , state)
90-     if  done (it. xs, state)
91-         state =  start (it. xs)
93+     s, d =  state
94+     if  done (it. xs, s)
95+         s =  start (it. xs)
9296    end 
93-     v =  next (it. xs, state)
97+     v, s =  next (it. xs, s)
98+     return  v, (s, false )
9499end 
95100
96- done (it:: Cycle , state) =  false 
101+ done (it:: Cycle , state) =  state[ 2 ] 
97102
98103
99- #  Repeat an object n (or infinately  many) times.
104+ #  Repeat an object n (or infinitely  many) times.
100105
101106type Repeat
102107    x
@@ -143,20 +148,20 @@ function start(it::Chain)
143148        end 
144149        i +=  1 
145150    end 
146-     ( i, xs_state) 
151+     return   i, xs_state
147152end 
148153
149154function  next (it:: Chain , state)
150155    i, xs_state =  state
151-     ( v, xs_state)  =  next (it. xss[i], xs_state)
156+     v, xs_state =  next (it. xss[i], xs_state)
152157    while  done (it. xss[i], xs_state)
153158        i +=  1 
154159        if  i >  length (it. xss)
155160            break 
156161        end 
157162        xs_state =  start (it. xss[i])
158163    end 
159-     ( v, (i, xs_state) )
164+     return   v, (i, xs_state)
160165end 
161166
162167done (it:: Chain , state) =  state[1 ] >  length (it. xss)
0 commit comments