That's the verbose thing I was expecting, Thanx! I couldn't find anything else (even this one) on initializing at runtime 2D slices. I hope it gets addressed some day to be able to use make to initialize this kind of stuff automatically.
I don't think it will be addressed. See the fourth paragraph on this page: http://commandcenter.blogspot.com/2011/12/esmereldas-imagination.html
That's the verbose thing I was expecting, Thanx!
I couldn't find anything else (even this one) on initializing at runtime 2D slices. I hope it gets addressed some day to be able to use make to initialize this kind of stuff automatically.
package main
import "fmt"
func main() {
data := [][]int{ []int{ 1, 2}, []int {2, 3}}
fmt.Printf("%v",data)
}
And just to make things a little clear, in the case above you don't
have a two dimensional slice, but in fact a slice of slices.
Think in terms of:
type IntSlice []int
type Slice2D []IntSlice
data := make(Slice2D,2)
The language is doing what you are asking it to do, in this case,
allocate a slice with 2 items which type is IntSlice,
Then, later you say to the language to allocate for each position of
the first slice a new slice of ints.
--
André Moraes
http://andredevchannel.blogspot.com/
Is this what you want?package main
import "fmt"
func main() {
data := [][]int{ []int{ 1, 2}, []int {2, 3}}
fmt.Printf("%v",data)
}