golang / tour

[mirror] A Tour of Go
BSD 3-Clause "New" or "Revised" License
1.53k stars 521 forks source link

Add an example for arrays with the `[...]T{a, b, c, d}` syntax #1606

Open adriancuadrado opened 2 months ago

adriancuadrado commented 2 months ago

https://github.com/golang/go/issues/66851

What is the URL of the page with the issue?

https://go.dev/tour/moretypes/6

What is your user agent?

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36

Screenshot

image

What did you do?

I read this article and found this code snippet:

b := [...]string{"Penn", "Teller"}

What did you see happen?

It is equivalent to this:

b := [2]string{"Penn", "Teller"}

but it's more convenient because you don't have to count the number of elements since that is done automatically for you by the compiler.

What did you expect to see?

I think it would be awesome to include this feature in A Tour of Go. More specifically here.

Just moving the issue to this repository as @seankhliao told me in his comment:

please file this on the your repo https://github.com/golang/tour/issues