Re: [go-nuts] Golang closures, counter-intuitive behaviour

2019-02-11 Thread Ian Lance Taylor
On Mon, Feb 11, 2019 at 4:48 PM Slawomir Pryczek wrote: > > When looking at this code below, you can see that the function will get LAST > value of i which is incremented inside the loop, but t is somehow copied and > taken inside a function so closure is created and it is bound to current >

[go-nuts] Golang closures, counter-intuitive behaviour

2019-02-11 Thread Slawomir Pryczek
Hi Guys, When looking at this code below, you can see that the function will get LAST value of i which is incremented inside the loop, but t is somehow copied and taken inside a function so closure is created and it is bound to current value of t, so we'll have its current value in function.