Please consider the module below. After having defined a function E
the following lines work as expected:
Eseq = Task(E)
for _ in 0:10
a = consume(Eseq)
println(a," ",typeof(a))
However wrapping these lines in a function leads to a ‘TypeError’.
Why? How can I avoid this error?
module A
function E()
D = Dict{Int, BigInt}(0=>1, -1=>0)
i = k = 0; s = 1
while true
E = 0; D[k + s] = 0; s = -s
for j in 0:i
E += D[k]; D[k] = E; k += s
end
produce(E)
i += 1
end
end
# --- works
Eseq = Task(E)
for _ in 0:10
a = consume(Eseq)
println(a," ",typeof(a))
end
# --- the same wrapped in a function
# --- does not work: TypeError
function test()
Eseq = Task(E)
for _ in 0::10
consume(Eseq)
println(a," ",typeof(a))
end
end
test()
end