Both function closures created refer to the same variable "i". You need a
let block to create a new local variable for each iteration of the whole
loop.
On Mon, Feb 16, 2015 at 12:57 PM Stepa Solntsev <[email protected]> wrote:

> Hi, I'd like the first call to return 1 and the second to return 2, but
> both return 2 !!! What could be the problem?
>
> function nice()
>       i=1
>       while true
>               f() = i
>               produce(f)
>               i+=1
>       end
> end
>  ye = Task(() -> nice())
> funcs = Function[]
>  for i in [1:2]
>       push!(funcs,consume(ye))
> end
>
> println(funcs[1]())
> println(funcs[2]())
>
>
>

Reply via email to