]> Cypherpunks repositories - gostls13.git/commitdiff
mention arrays of arrays and slices of slices
authorRob Pike <r@golang.org>
Fri, 20 Nov 2009 23:47:15 +0000 (15:47 -0800)
committerRob Pike <r@golang.org>
Fri, 20 Nov 2009 23:47:15 +0000 (15:47 -0800)
Fixes #113.

R=gri, rsc
CC=golang-dev
https://golang.org/cl/159049

doc/go_spec.html

index 5eaeea04bc09d6cbe5cff1114e930b193122f658..8a247461daeb53b23e3dce6b861cc05bd7c9befa 100644 (file)
@@ -607,12 +607,16 @@ integer value.  The length of array <code>a</code> can be discovered
 using the built-in function <code>len(a)</code>, which is a
 compile-time constant.  The elements can be indexed by integer
 indices 0 through the <code>len(a)-1</code> (ยง<a href="#Indexes">Indexes</a>).
+Array types are always one-dimensional but may be composed to form
+multi-dimensional types.
 </p>
 
 <pre>
 [32]byte
 [2*N] struct { x, y int32 }
 [1000]*float64
+[3][5]int
+[2][2][2]float64  // same as [2]([2]([2]float64))
 </pre>
 
 <h3 id="Slice_types">Slice types</h3>
@@ -690,6 +694,13 @@ make([]int, 50, 100)
 new([100]int)[0:50]
 </pre>
 
+<p>
+Like arrays, slices are always one-dimensional but may be composed to construct
+higher-dimensional objects.
+With arrays of arrays, the inner arrays are, by construction, always the same length;
+however with slices of slices (or arrays of slices), the lengths may vary dynamically.
+Moreover, the inner slices must be allocated individually (with <code>make</code>).
+</p>
 
 <h3 id="Struct_types">Struct types</h3>