This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Bracket Ellipsis Bracket Notation

 
Ranch Hand
Posts: 224
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm taking a look at the Go Language Spec on "https://golang.org/ref/spec#Pointer_types" where it says, "The notation ... specifies an array length equal to the maximum element index plus one." Then, as an example, it lists:

This has got me completely confused. What exactly does the bracket ellipsis bracket mean? Can anybody explain this to me?
 
Sheriff
Posts: 14759
245
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the same as declaring:

The difference is that with the "...", it will adjust automatically if you add more literal values.

Play around with this: https://play.golang.org/p/OH_4JB6U16
 
Kevin Simonson
Ranch Hand
Posts: 224
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:It's the same as declaring:

The difference is that with the "...", it will adjust automatically if you add more literal values.

Play around with this: https://play.golang.org/p/OH_4JB6U16


Got it; thanks for the feedback.
 
Junilu Lacar
Sheriff
Posts: 14759
245
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's another page that has an example of the notation: https://blog.golang.org/go-slices-usage-and-internals (under the "Slices" section).

BTW, the ... operator is not an "ellipsis" just as the Receive operator, <-, is not a left arrow. An ellipsis is a single character, '…', whereas the ... operator is made up of three consecutive '.' characters. I can't find any reference that gives a formal name to this operator and it appears to have at least three meanings, depending on the context in which it is used.  With array declarations as we have discussed here, it causes the compiler to count the number of elements in an array literal to automatically determine the size of the array to allocate. In a formal parameter list, it indicates a variadic parameter of a function that can take a variable number of arguments. As part of a function call argument, it expands a slice or array so that each element is a separate value that is passed to a variadic parameter.
 
I think she's lovely. It's this tiny ad that called her crazy:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!