github.com/gmemcc/yaegi@v0.12.1-0.20221128122509-aa99124c5d16/_test/closure11.go (about)

     1  package main
     2  
     3  type T struct {
     4  	F func()
     5  }
     6  
     7  func main() {
     8  	foos := []T{}
     9  
    10  	for i := 0; i < 3; i++ {
    11  		a := i
    12  		foos = append(foos, T{func() { println(i, a) }})
    13  	}
    14  	foos[0].F()
    15  	foos[1].F()
    16  	foos[2].F()
    17  }
    18  
    19  // Output:
    20  // 3 0
    21  // 3 1
    22  // 3 2