Jump to content

Generator/Exponential: Difference between revisions

Updated to compile with Nim 1.4: added an Iterator type, added parameter and function types, changed ".. <" to "..< ", etc.
(Added Wren)
(Updated to compile with Nim 1.4: added an Iterator type, added parameter and function types, changed ".. <" to "..< ", etc.)
Line 2,419:
 
=={{header|Nim}}==
<lang nim>proctype `^`*(base:Iterator int,= exp: intiterator(): int =
 
proc `^`*(base: Natural; exp: Natural): int =
var (base, exp) = (base, exp)
result = 1
 
while exp != 0:
if (exp and 1) != 0:
Line 2,429 ⟶ 2,430:
base *= base
 
proc next(s: Iterator): int =
for n in s(): return n
 
proc powers(m: Natural): autoIterator =
iterator it(): int {.closure.} =
for n in 0 .. < int.high:
yield n ^ m
returnresult = it
 
iterator filtered(s1, s2: Iterator): int =
var v = next(s1)
var f = next(s2)
Line 2,454 ⟶ 2,455:
i = 1
for x in filtered(squares, cubes):
if i > 20: echo x
if i echo>= x30: break
if i >= 30:
break
inc i</lang>
 
{{out}}
<pre>529
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.