Converting a type to an array - GO syntaxConvert string to integer type in Go?How to assign string to bytes arrayHow to convert an int value to string in Go?Strange type definition syntax in Golang (name, then type, then string literal)Type converting slices of interfacesHow to convert a zero-terminated byte array to string?cannot convert data (type interface ) to type string: need type assertionHow to find a type of an object in Go?Convert array to slice in GoFunction declaration syntax: things in parenthesis before function name

Probability of rolling a specific combination of results with nd6

What was the deeper meaning of Hermione wanting the cloak?

Get the encrypted payload from an unencrypted wrapper PDF document

What is the origin of the "being immortal sucks" trope?

Is it safe to unplug a blinking USB drive after 'safely' ejecting it?

Should the pagination be reset when changing the order?

Applications of mathematics in clinical setting

Most efficient way to convert from 3.5-4.2V (singe cell LiPo) to stable 3.3V for currents up to 500 mA?

Inquiry answerer

What's the word for a student who doesn't register but goes to a class anyway?

Is a global DNS record a security risk for phpMyAdmin?

Why does Canada require a minimum rate of climb for ultralights of 300 ft/min?

How often is duct tape used during crewed space missions?

What's the purpose of autocorrelation?

How could artificial intelligence harm us?

Which museums have artworks of all four ninja turtles' namesakes?

Do household ovens ventilate heat to the outdoors?

Can we store a whole string with the help of a single character pointer? If yes , How?

Debussy as term for bathroom?

Is there a connection between IT and Ghostbusters?

Is it possible that the shadow of The Moon is a single dot during solar eclipse?

Are lay articles good enough to be the main source of information for PhD research?

Dear Fellow PSE Users,

Is there any actual security benefit to restricting foreign IPs?



Converting a type to an array - GO syntax


Convert string to integer type in Go?How to assign string to bytes arrayHow to convert an int value to string in Go?Strange type definition syntax in Golang (name, then type, then string literal)Type converting slices of interfacesHow to convert a zero-terminated byte array to string?cannot convert data (type interface ) to type string: need type assertionHow to find a type of an object in Go?Convert array to slice in GoFunction declaration syntax: things in parenthesis before function name






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-3















In the below syntax_1,



 array := [...]float647.0, 8.5, 9.1


and syntax_2,



type People interface 
SayHello()
ToString()


type Student struct
Person
university string
course string


type Developer struct
Person
company string
platform string



func main()

alex := StudentPerson"alex", 21, "111-222-XXX", "MIT","BS CS"
john := DeveloperPerson"John", 35, "111-222-XXX", "Accel North America", "Golang"
jithesh := DeveloperPerson"Jithesh", 33, "111-222-XXX", "Accel North America", "Hadoop"
//An array with People types
peopleArr := [...]Peoplealex, john,jithesh




1) What does this syntax float647.0, 8.5, 9.1 & Peoplealex, john,jithesh mean? this looks like a paradigm(a way of programming) more than a syntax



2) Can you provide reference to the meaning/purpose of [...] syntax? I see converting something to an [] type










share|improve this question





















  • 4





    It's all here: golang.org/ref/spec. 1) A composite literal, it is syntax, not "paradigm". 2) Create an array whose length is the same as the number of elements provided to the literal.

    – mkopriva
    Mar 28 at 14:17












  • @mkopriva golang.org/search?q=%5B...%5D

    – overexchange
    Mar 28 at 14:17






  • 2





    1, 2, 3 is a composite literal, and "The notation ... specifies an array length equal to the maximum element index plus one."

    – icza
    Mar 28 at 14:18







  • 1





    @overexchange what are you implying with that link? That it's hard to find? Try the link in my first comment and try searching that page with CTRL/CMD+F, that's more efficient.

    – mkopriva
    Mar 28 at 14:20






  • 1





    Unnamed arrays* can't implement interfaces. It's objects that implement interfaces, so you have an array of objects and those objects implement the interface. Edit: I use objects here, but it may be more correct to say structs.

    – Devon
    Mar 28 at 14:31


















-3















In the below syntax_1,



 array := [...]float647.0, 8.5, 9.1


and syntax_2,



type People interface 
SayHello()
ToString()


type Student struct
Person
university string
course string


type Developer struct
Person
company string
platform string



func main()

alex := StudentPerson"alex", 21, "111-222-XXX", "MIT","BS CS"
john := DeveloperPerson"John", 35, "111-222-XXX", "Accel North America", "Golang"
jithesh := DeveloperPerson"Jithesh", 33, "111-222-XXX", "Accel North America", "Hadoop"
//An array with People types
peopleArr := [...]Peoplealex, john,jithesh




1) What does this syntax float647.0, 8.5, 9.1 & Peoplealex, john,jithesh mean? this looks like a paradigm(a way of programming) more than a syntax



2) Can you provide reference to the meaning/purpose of [...] syntax? I see converting something to an [] type










share|improve this question





















  • 4





    It's all here: golang.org/ref/spec. 1) A composite literal, it is syntax, not "paradigm". 2) Create an array whose length is the same as the number of elements provided to the literal.

    – mkopriva
    Mar 28 at 14:17












  • @mkopriva golang.org/search?q=%5B...%5D

    – overexchange
    Mar 28 at 14:17






  • 2





    1, 2, 3 is a composite literal, and "The notation ... specifies an array length equal to the maximum element index plus one."

    – icza
    Mar 28 at 14:18







  • 1





    @overexchange what are you implying with that link? That it's hard to find? Try the link in my first comment and try searching that page with CTRL/CMD+F, that's more efficient.

    – mkopriva
    Mar 28 at 14:20






  • 1





    Unnamed arrays* can't implement interfaces. It's objects that implement interfaces, so you have an array of objects and those objects implement the interface. Edit: I use objects here, but it may be more correct to say structs.

    – Devon
    Mar 28 at 14:31














-3












-3








-3








In the below syntax_1,



 array := [...]float647.0, 8.5, 9.1


and syntax_2,



type People interface 
SayHello()
ToString()


type Student struct
Person
university string
course string


type Developer struct
Person
company string
platform string



func main()

alex := StudentPerson"alex", 21, "111-222-XXX", "MIT","BS CS"
john := DeveloperPerson"John", 35, "111-222-XXX", "Accel North America", "Golang"
jithesh := DeveloperPerson"Jithesh", 33, "111-222-XXX", "Accel North America", "Hadoop"
//An array with People types
peopleArr := [...]Peoplealex, john,jithesh




1) What does this syntax float647.0, 8.5, 9.1 & Peoplealex, john,jithesh mean? this looks like a paradigm(a way of programming) more than a syntax



2) Can you provide reference to the meaning/purpose of [...] syntax? I see converting something to an [] type










share|improve this question
















In the below syntax_1,



 array := [...]float647.0, 8.5, 9.1


and syntax_2,



type People interface 
SayHello()
ToString()


type Student struct
Person
university string
course string


type Developer struct
Person
company string
platform string



func main()

alex := StudentPerson"alex", 21, "111-222-XXX", "MIT","BS CS"
john := DeveloperPerson"John", 35, "111-222-XXX", "Accel North America", "Golang"
jithesh := DeveloperPerson"Jithesh", 33, "111-222-XXX", "Accel North America", "Hadoop"
//An array with People types
peopleArr := [...]Peoplealex, john,jithesh




1) What does this syntax float647.0, 8.5, 9.1 & Peoplealex, john,jithesh mean? this looks like a paradigm(a way of programming) more than a syntax



2) Can you provide reference to the meaning/purpose of [...] syntax? I see converting something to an [] type







go






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 14:17







overexchange

















asked Mar 28 at 14:16









overexchangeoverexchange

4,2337 gold badges37 silver badges96 bronze badges




4,2337 gold badges37 silver badges96 bronze badges










  • 4





    It's all here: golang.org/ref/spec. 1) A composite literal, it is syntax, not "paradigm". 2) Create an array whose length is the same as the number of elements provided to the literal.

    – mkopriva
    Mar 28 at 14:17












  • @mkopriva golang.org/search?q=%5B...%5D

    – overexchange
    Mar 28 at 14:17






  • 2





    1, 2, 3 is a composite literal, and "The notation ... specifies an array length equal to the maximum element index plus one."

    – icza
    Mar 28 at 14:18







  • 1





    @overexchange what are you implying with that link? That it's hard to find? Try the link in my first comment and try searching that page with CTRL/CMD+F, that's more efficient.

    – mkopriva
    Mar 28 at 14:20






  • 1





    Unnamed arrays* can't implement interfaces. It's objects that implement interfaces, so you have an array of objects and those objects implement the interface. Edit: I use objects here, but it may be more correct to say structs.

    – Devon
    Mar 28 at 14:31













  • 4





    It's all here: golang.org/ref/spec. 1) A composite literal, it is syntax, not "paradigm". 2) Create an array whose length is the same as the number of elements provided to the literal.

    – mkopriva
    Mar 28 at 14:17












  • @mkopriva golang.org/search?q=%5B...%5D

    – overexchange
    Mar 28 at 14:17






  • 2





    1, 2, 3 is a composite literal, and "The notation ... specifies an array length equal to the maximum element index plus one."

    – icza
    Mar 28 at 14:18







  • 1





    @overexchange what are you implying with that link? That it's hard to find? Try the link in my first comment and try searching that page with CTRL/CMD+F, that's more efficient.

    – mkopriva
    Mar 28 at 14:20






  • 1





    Unnamed arrays* can't implement interfaces. It's objects that implement interfaces, so you have an array of objects and those objects implement the interface. Edit: I use objects here, but it may be more correct to say structs.

    – Devon
    Mar 28 at 14:31








4




4





It's all here: golang.org/ref/spec. 1) A composite literal, it is syntax, not "paradigm". 2) Create an array whose length is the same as the number of elements provided to the literal.

– mkopriva
Mar 28 at 14:17






It's all here: golang.org/ref/spec. 1) A composite literal, it is syntax, not "paradigm". 2) Create an array whose length is the same as the number of elements provided to the literal.

– mkopriva
Mar 28 at 14:17














@mkopriva golang.org/search?q=%5B...%5D

– overexchange
Mar 28 at 14:17





@mkopriva golang.org/search?q=%5B...%5D

– overexchange
Mar 28 at 14:17




2




2





1, 2, 3 is a composite literal, and "The notation ... specifies an array length equal to the maximum element index plus one."

– icza
Mar 28 at 14:18






1, 2, 3 is a composite literal, and "The notation ... specifies an array length equal to the maximum element index plus one."

– icza
Mar 28 at 14:18





1




1





@overexchange what are you implying with that link? That it's hard to find? Try the link in my first comment and try searching that page with CTRL/CMD+F, that's more efficient.

– mkopriva
Mar 28 at 14:20





@overexchange what are you implying with that link? That it's hard to find? Try the link in my first comment and try searching that page with CTRL/CMD+F, that's more efficient.

– mkopriva
Mar 28 at 14:20




1




1





Unnamed arrays* can't implement interfaces. It's objects that implement interfaces, so you have an array of objects and those objects implement the interface. Edit: I use objects here, but it may be more correct to say structs.

– Devon
Mar 28 at 14:31






Unnamed arrays* can't implement interfaces. It's objects that implement interfaces, so you have an array of objects and those objects implement the interface. Edit: I use objects here, but it may be more correct to say structs.

– Devon
Mar 28 at 14:31













1 Answer
1






active

oldest

votes


















0
















Squiggly brackets are used to define a composite literal. A value that contains more than one value inside it. In your first example an array of float values is created
[...]float647.0, 8.5, 9.1 is a literal for an array of floats with 3 elements. In your second example, a few literals for predefined struct types are created and another array. Person"alex", 21, "111-222-XXX" is a literal for a struct of type Person. And [...]Peoplealex, john,jithesh is an array of type People containing 3 elements.






share|improve this answer

























  • Can I say , Peoplealex, john, jitesh is a composite literal for a struct of type People? where name alex is pointing to a literal(object) for a struct of type Student?

    – overexchange
    Mar 28 at 15:15












  • People type is an interface, so anything that implements this interface can be a member of this array. For this code to work both Developer and Student need to implement People interface either directly or through the embedded Person struct.

    – Mad Wombat
    Mar 28 at 15:20






  • 1





    But Peoplealex, john, jitesh on its own is not valid. It needs [...] to make it an array of People. Or simply [] to make it a slice of People.

    – Mad Wombat
    Mar 28 at 15:21











  • [...]People is an array. []People is a slice. These are two different types.

    – Mad Wombat
    Mar 28 at 15:23











  • [...]People would create an empty array of zero elements, but [...]Peoplealex, john, jitesh would create a populated array of three elements

    – Mad Wombat
    Mar 28 at 15:24










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55399823%2fconverting-a-type-to-an-array-go-syntax%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0
















Squiggly brackets are used to define a composite literal. A value that contains more than one value inside it. In your first example an array of float values is created
[...]float647.0, 8.5, 9.1 is a literal for an array of floats with 3 elements. In your second example, a few literals for predefined struct types are created and another array. Person"alex", 21, "111-222-XXX" is a literal for a struct of type Person. And [...]Peoplealex, john,jithesh is an array of type People containing 3 elements.






share|improve this answer

























  • Can I say , Peoplealex, john, jitesh is a composite literal for a struct of type People? where name alex is pointing to a literal(object) for a struct of type Student?

    – overexchange
    Mar 28 at 15:15












  • People type is an interface, so anything that implements this interface can be a member of this array. For this code to work both Developer and Student need to implement People interface either directly or through the embedded Person struct.

    – Mad Wombat
    Mar 28 at 15:20






  • 1





    But Peoplealex, john, jitesh on its own is not valid. It needs [...] to make it an array of People. Or simply [] to make it a slice of People.

    – Mad Wombat
    Mar 28 at 15:21











  • [...]People is an array. []People is a slice. These are two different types.

    – Mad Wombat
    Mar 28 at 15:23











  • [...]People would create an empty array of zero elements, but [...]Peoplealex, john, jitesh would create a populated array of three elements

    – Mad Wombat
    Mar 28 at 15:24















0
















Squiggly brackets are used to define a composite literal. A value that contains more than one value inside it. In your first example an array of float values is created
[...]float647.0, 8.5, 9.1 is a literal for an array of floats with 3 elements. In your second example, a few literals for predefined struct types are created and another array. Person"alex", 21, "111-222-XXX" is a literal for a struct of type Person. And [...]Peoplealex, john,jithesh is an array of type People containing 3 elements.






share|improve this answer

























  • Can I say , Peoplealex, john, jitesh is a composite literal for a struct of type People? where name alex is pointing to a literal(object) for a struct of type Student?

    – overexchange
    Mar 28 at 15:15












  • People type is an interface, so anything that implements this interface can be a member of this array. For this code to work both Developer and Student need to implement People interface either directly or through the embedded Person struct.

    – Mad Wombat
    Mar 28 at 15:20






  • 1





    But Peoplealex, john, jitesh on its own is not valid. It needs [...] to make it an array of People. Or simply [] to make it a slice of People.

    – Mad Wombat
    Mar 28 at 15:21











  • [...]People is an array. []People is a slice. These are two different types.

    – Mad Wombat
    Mar 28 at 15:23











  • [...]People would create an empty array of zero elements, but [...]Peoplealex, john, jitesh would create a populated array of three elements

    – Mad Wombat
    Mar 28 at 15:24













0














0










0









Squiggly brackets are used to define a composite literal. A value that contains more than one value inside it. In your first example an array of float values is created
[...]float647.0, 8.5, 9.1 is a literal for an array of floats with 3 elements. In your second example, a few literals for predefined struct types are created and another array. Person"alex", 21, "111-222-XXX" is a literal for a struct of type Person. And [...]Peoplealex, john,jithesh is an array of type People containing 3 elements.






share|improve this answer













Squiggly brackets are used to define a composite literal. A value that contains more than one value inside it. In your first example an array of float values is created
[...]float647.0, 8.5, 9.1 is a literal for an array of floats with 3 elements. In your second example, a few literals for predefined struct types are created and another array. Person"alex", 21, "111-222-XXX" is a literal for a struct of type Person. And [...]Peoplealex, john,jithesh is an array of type People containing 3 elements.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 28 at 14:44









Mad WombatMad Wombat

7,3315 gold badges42 silver badges75 bronze badges




7,3315 gold badges42 silver badges75 bronze badges















  • Can I say , Peoplealex, john, jitesh is a composite literal for a struct of type People? where name alex is pointing to a literal(object) for a struct of type Student?

    – overexchange
    Mar 28 at 15:15












  • People type is an interface, so anything that implements this interface can be a member of this array. For this code to work both Developer and Student need to implement People interface either directly or through the embedded Person struct.

    – Mad Wombat
    Mar 28 at 15:20






  • 1





    But Peoplealex, john, jitesh on its own is not valid. It needs [...] to make it an array of People. Or simply [] to make it a slice of People.

    – Mad Wombat
    Mar 28 at 15:21











  • [...]People is an array. []People is a slice. These are two different types.

    – Mad Wombat
    Mar 28 at 15:23











  • [...]People would create an empty array of zero elements, but [...]Peoplealex, john, jitesh would create a populated array of three elements

    – Mad Wombat
    Mar 28 at 15:24

















  • Can I say , Peoplealex, john, jitesh is a composite literal for a struct of type People? where name alex is pointing to a literal(object) for a struct of type Student?

    – overexchange
    Mar 28 at 15:15












  • People type is an interface, so anything that implements this interface can be a member of this array. For this code to work both Developer and Student need to implement People interface either directly or through the embedded Person struct.

    – Mad Wombat
    Mar 28 at 15:20






  • 1





    But Peoplealex, john, jitesh on its own is not valid. It needs [...] to make it an array of People. Or simply [] to make it a slice of People.

    – Mad Wombat
    Mar 28 at 15:21











  • [...]People is an array. []People is a slice. These are two different types.

    – Mad Wombat
    Mar 28 at 15:23











  • [...]People would create an empty array of zero elements, but [...]Peoplealex, john, jitesh would create a populated array of three elements

    – Mad Wombat
    Mar 28 at 15:24
















Can I say , Peoplealex, john, jitesh is a composite literal for a struct of type People? where name alex is pointing to a literal(object) for a struct of type Student?

– overexchange
Mar 28 at 15:15






Can I say , Peoplealex, john, jitesh is a composite literal for a struct of type People? where name alex is pointing to a literal(object) for a struct of type Student?

– overexchange
Mar 28 at 15:15














People type is an interface, so anything that implements this interface can be a member of this array. For this code to work both Developer and Student need to implement People interface either directly or through the embedded Person struct.

– Mad Wombat
Mar 28 at 15:20





People type is an interface, so anything that implements this interface can be a member of this array. For this code to work both Developer and Student need to implement People interface either directly or through the embedded Person struct.

– Mad Wombat
Mar 28 at 15:20




1




1





But Peoplealex, john, jitesh on its own is not valid. It needs [...] to make it an array of People. Or simply [] to make it a slice of People.

– Mad Wombat
Mar 28 at 15:21





But Peoplealex, john, jitesh on its own is not valid. It needs [...] to make it an array of People. Or simply [] to make it a slice of People.

– Mad Wombat
Mar 28 at 15:21













[...]People is an array. []People is a slice. These are two different types.

– Mad Wombat
Mar 28 at 15:23





[...]People is an array. []People is a slice. These are two different types.

– Mad Wombat
Mar 28 at 15:23













[...]People would create an empty array of zero elements, but [...]Peoplealex, john, jitesh would create a populated array of three elements

– Mad Wombat
Mar 28 at 15:24





[...]People would create an empty array of zero elements, but [...]Peoplealex, john, jitesh would create a populated array of three elements

– Mad Wombat
Mar 28 at 15:24








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55399823%2fconverting-a-type-to-an-array-go-syntax%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?