Re: [go-nuts] Initialize Variables in case clause of a switch

2016-08-09 Thread Dan Kortschak
On Fri, 2016-08-05 at 08:57 -0700, dc0d wrote: > In Go we can write: > > if _, ok := input.(*data); ok { > //... > } > > Why is it we can't do that in the case clause of a switch statement: > > switch { > case x1,ok:=input.(*data1); ok && otherCond1: > case x2,ok:=input.(*data2); ok && otherCond

Re: [go-nuts] Initialize Variables in case clause of a switch

2016-08-05 Thread Rob Pike
It was talked about very early, and eventually made available as a feature of select statements, where grabbing the received value might be necessary. But the argument for switch statements never seemed strong enough. -rob -- You received this message because you are subscribed to the Google Gro

Re: [go-nuts] Initialize Variables in case clause of a switch

2016-08-05 Thread Sam Whited
On Fri, Aug 5, 2016 at 11:40 AM, Ian Lance Taylor wrote: > I don't think there is a reason as such. I don't recall anybody ever > suggesting it. I also run into cases where this would make things more readable on occasion; can't think of any examples off the top of my head though. —Sam -- Sam

Re: [go-nuts] Initialize Variables in case clause of a switch

2016-08-05 Thread Andy Balholm
I’ve wished for it too, but I just use an else/if chain in that case. Andy -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.c

Re: [go-nuts] Initialize Variables in case clause of a switch

2016-08-05 Thread Ian Lance Taylor
On Fri, Aug 5, 2016 at 8:57 AM, dc0d wrote: > In Go we can write: > > if _, ok := input.(*data); ok { > //... > } > > Why is it we can't do that in the case clause of a switch statement: > > switch { > case x1,ok:=input.(*data1); ok && otherCond1: > case x2,ok:=input.(*data2); ok && otherCond2: >

[go-nuts] Initialize Variables in case clause of a switch

2016-08-05 Thread dc0d
In Go we can write: if _, ok := input.(*data); ok { //... } Why is it we can't do that in the case clause of a switch statement: switch { case x1,ok:=input.(*data1); ok && otherCond1: case x2,ok:=input.(*data2); ok && otherCond2: } (I've read the language specification - which BTW speaks about