Anonymous user
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>
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):
iterator it(): int {.closure.} =
for n in 0 ..
yield n ^ m
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
inc i</lang>
{{out}}
<pre>529
|