github.com/goplus/llgo@v0.8.3/cl/_testrt/intgen/in.go (about) 1 package main 2 3 import ( 4 "github.com/goplus/llgo/internal/runtime/c" 5 ) 6 7 type generator struct { 8 val c.Int 9 } 10 11 func (g *generator) next() c.Int { 12 g.val++ 13 return g.val 14 } 15 16 func genInts(n int, gen func() c.Int) []c.Int { 17 a := make([]c.Int, n) 18 for i := range a { 19 a[i] = gen() 20 } 21 return a 22 } 23 24 func main() { 25 for _, v := range genInts(5, c.Rand) { 26 c.Printf(c.Str("%d\n"), v) 27 } 28 29 initVal := c.Int(1) 30 ints := genInts(5, func() c.Int { 31 initVal *= 2 32 return initVal 33 }) 34 for _, v := range ints { 35 c.Printf(c.Str("%d\n"), v) 36 } 37 38 g := &generator{val: 1} 39 for _, v := range genInts(5, g.next) { 40 c.Printf(c.Str("%d\n"), v) 41 } 42 }