Re: [go-nuts] golang closure variable

2016-11-03 Thread adonovan via golang-nuts
On Thursday, 3 November 2016 03:05:47 UTC-4, 刘桂祥 wrote: > > > package main > > import "time" > > func main() { > s := []int{100, 200} > println(&s) > go func() { > s[0] = 300 > s = []int{300, 400} > }() > time.Sleep(1 * time.Second) > } > > just curious about this ,can you help explain the assemb

Re: [go-nuts] golang closure variable

2016-11-03 Thread 刘桂祥
package main import "time" func main() { s := []int{100, 200} println(&s) go func() { s[0] = 300 s = []int{300, 400} }() time.Sleep(1 * time.Second) } just curious about this ,can you help explain the assemble code here "".main t=1 size=241 args=0x0 locals=0x28 0x 0 (main.go:5) TEXT "

Re: [go-nuts] golang closure variable

2016-11-02 Thread Ian Lance Taylor
On Wed, Nov 2, 2016 at 11:48 PM, 刘桂祥 wrote: > I just want to look what variable datastructure is passed to the closure > func but I am confused with the assemble code > > > // example.go > > package main > > > import "time" > > > func main() { > > s := []int{100, 200} > > func() { > > s[0] = 300

Re: [go-nuts] golang closure variable

2016-11-02 Thread 刘桂祥
I just want to look what variable datastructure is passed to the closure func but I am confused with the assemble code // example.go package main import "time" func main() { s := []int{100, 200} func() { s[0] = 300 s = []int{300, 400} }() time.Sleep(1 * time.Second) } And I

Re: [go-nuts] golang closure variable

2016-11-02 Thread Ian Lance Taylor
On Wed, Nov 2, 2016 at 8:03 PM, 刘桂祥 wrote: > > In golang closure func ,the needed outer variable is passed by reference > > but when the variable self is a reference in example.go , the closure func > paras is *[&map[int]int,...] is so ? I'm not completely sure what you are asking, but I think t

[go-nuts] golang closure variable

2016-11-02 Thread 刘桂祥
In golang closure func ,the needed outer variable is passed by reference but when the variable self is a reference in example.go , the closure func p