Re: [go-nuts] Golang language specification Document: Composite Literals example is not understandable

2021-06-23 Thread jake...@gmail.com
No that is exactly what I meant. I would never use it, as it seems like obfuscation, but there are those who like to be clever. On Tuesday, June 22, 2021 at 5:36:56 PM UTC-4 Rob 'Commander' Pike wrote: > That creates a slice 101 integers long, which probably isn't what you > meant, which might

Re: [go-nuts] Golang language specification Document: Composite Literals example is not understandable

2021-06-23 Thread Jan Mercl
On Wed, Jun 23, 2021 at 7:06 AM Vaibhav Maurya wrote: > I appreciate the whole discussion, it was really insightful. Since Golang is > not my first language, I had a preconceived notion about key-value pair > initialization. > Here I would like to disagree with the syntax, it would be good

Re: [go-nuts] Golang language specification Document: Composite Literals example is not understandable

2021-06-23 Thread 'Axel Wagner' via golang-nuts
FWIW I don't believe I ever saw key-value initialization of arrays or slices in the wild. Not saying *no one* uses it, but it's certainly rare enough that I wouldn't worry about getting confused by it in practice. On Wed, Jun 23, 2021 at 7:07 AM Vaibhav Maurya wrote: > > I appreciate the whole

Re: [go-nuts] Golang language specification Document: Composite Literals example is not understandable

2021-06-22 Thread Vaibhav Maurya
I appreciate the whole discussion, it was really insightful. Since Golang is not my first language, I had a preconceived notion about key-value pair initialization. Here I would like to disagree with the syntax, it would be good that with the innovation in the language, the general idea of an

Re: [go-nuts] Golang language specification Document: Composite Literals example is not understandable

2021-06-22 Thread Rob Pike
That creates a slice 101 integers long, which probably isn't what you meant, which might help explain why you never came across it before. Smile. -rob On Wed, Jun 23, 2021 at 7:07 AM jake...@gmail.com wrote: > I'm surprised that I have never come across this as a way to create a > slice with

Re: [go-nuts] Golang language specification Document: Composite Literals example is not understandable

2021-06-22 Thread jake...@gmail.com
I'm surprised that I have never come across this as a way to create a slice with an initial length: x := []int{100:0} On Tuesday, June 22, 2021 at 12:43:17 PM UTC-4 axel.wa...@googlemail.com wrote: > Oh and also: > > Likewise, I think this only works for array literals; I don’t think >>

Re: [go-nuts] Golang language specification Document: Composite Literals example is not understandable

2021-06-22 Thread Bakul Shah
If you are familiar with C99’s designated initializers, this is similar but less general and less confusing. > On Jun 22, 2021, at 8:40 AM, Vaibhav Maurya wrote: > Hi, > > Please help me to understand the following syntax mentioned in the Golang > language specification document. > >

Re: [go-nuts] Golang language specification Document: Composite Literals example is not understandable

2021-06-22 Thread David Riley
On Jun 22, 2021, at 12:42, Axel Wagner wrote: > >  > Oh and also: > >> Likewise, I think this only works for array literals; I don’t think (though >> again have not tried it) that you can declare slice literals with only >> selected members initialized. > > Works fine too:

Re: [go-nuts] Golang language specification Document: Composite Literals example is not understandable

2021-06-22 Thread 'Axel Wagner' via golang-nuts
Oh and also: Likewise, I think this only works for array literals; I don’t think (though > again have not tried it) that you can declare slice literals with only > selected members initialized. Works fine too: https://play.golang.org/p/ANw54ShkTvY :) On Tue, Jun 22, 2021 at 6:41 PM Axel Wagner

Re: [go-nuts] Golang language specification Document: Composite Literals example is not understandable

2021-06-22 Thread 'Axel Wagner' via golang-nuts
> > (I assume with a runtime rather than a compiler error, but I haven’t tried > it) Nope, compiler catches the overflow: https://play.golang.org/p/taorqygqxFz On Tue, Jun 22, 2021 at 6:39 PM David Riley wrote: > On Jun 22, 2021, at 11:39, Vaibhav Maurya wrote: > > > Hi, > > Please help me

Re: [go-nuts] Golang language specification Document: Composite Literals example is not understandable

2021-06-22 Thread David Riley
On Jun 22, 2021, at 11:39, Vaibhav Maurya wrote: > > Hi, > > Please help me to understand the following syntax mentioned in the Golang > language specification document. > > https://golang.org/ref/spec#Composite_literals > > following is the search string for CTRL + F > // vowels[ch] is

Re: [go-nuts] Golang language specification Document: Composite Literals example is not understandable

2021-06-22 Thread 'Axel Wagner' via golang-nuts
It's in the section you link to: The key is interpreted as a field name for struct literals*, an index for > array and slice literals*, and a key for map literals. (emphasis mine). The syntax allows you to specify keys for arrays and slices and interprets them as indices. Rune-literals (like

Re: [go-nuts] Golang language specification Document: Composite Literals example is not understandable

2021-06-22 Thread Jan Mercl
On Tue, Jun 22, 2021 at 5:40 PM Vaibhav Maurya wrote: > https://golang.org/ref/spec#Composite_literals > > following is the search string for CTRL + F > // vowels[ch] is true if ch is a vowel \ > > Following declaration and initialization is confusing. > vowels := [128]bool{'a': true, 'e': true,

[go-nuts] Golang language specification Document: Composite Literals example is not understandable

2021-06-22 Thread Vaibhav Maurya
Hi, Please help me to understand the following syntax mentioned in the Golang language specification document. https://golang.org/ref/spec#Composite_literals following is the search string for CTRL + F // vowels[ch] is true if ch is a vowel \ Following declaration and initialization is