I'm trying to get my head around writing lambdas with closures in nim. Creating
an "iota" function seems like a good start. Here's what I've got so far:
proc ioto(): proc() =
var i = 0
proc fn (): int =
i = i + 1
return i
result = fn
var j = iota()
echo j() , j()
var k = iota()
echo k(), k(), k()
echo j()
Run
The first problem is I get a compiler error as a type mismatch in the
declaration of iota. iota returns a proc that returns an int, but I haven't
been able to figure out how to declare it as such.
The second thing is: is "i" global to all created functions, or local to each
one? The latter is the desired behaviour.