An array is a fixed-length sequence of values with one element type. The type [n]T contains n values of type T, so [5]string and [4]image.Point are different types. Because length belongs to the type, arrays cannot be resized. section 3.2.2 section 9.3.1
Use arrays when a small, fixed-size collection fits the implementation:
- Declare an array with a length, such as var a [5]string. section 3.2.2
- Use [...]image.Point when the compiler should determine the length; four neighboring pixel coordinates form a [4]image.Point array. section 9.3.1
- Range over arrays with the same index-and-value syntax used for slices. section 3.5
Fixed neighbors in a maze
func neighbours(p image.Point) [4]image.Point { return [...]image.Point{ {p.X, p.Y + 1}, {p.X, p.Y - 1}, {p.X + 1, p.Y}, {p.X - 1, p.Y}, } } The fixed array represents exactly four orthogonal neighbors. Some returned points may lie outside the image; later image access determines how those positions are handled. section 9.3.1







































