Re: [go-nuts] Re: Go if else syntax .. suggested replacement

2019-04-24 Thread Matt Harden
On Wed, Apr 24, 2019 at 8:42 PM David Koblas  wrote:

> IMHO I've wanted a switch expression, rather than a switch statement for a
> while.
>
I've wanted that too, but what we already have really isn't that bad.

> value := switch test {
>   case true => "red"
>   case false => "blue"
> }
>
> value := "blue"
if test {
  value = "red"
}

> value := switch item.(type) {
>   case int => item
>   case string => strconv.Atoi(item)
>   case time.Time => {
> ... something more involved ... returning an int
>   }
> }
>
> Note that the above won't work; you must have a default case as well, for
almost any switch expression.

value := 0
switch v := item.(type) {
  case int:
value = v
  case string:
value = strconv.Atoi(v)
  case time.Time:
...
}

> Sure, not as compact as ternary -- but far more powerful and useful.
> On 4/24/19 9:40 PM, Michael Jones wrote:
>
> switch test {
> case true:
>   //..code block for test=true
> case false:
>   //..code block for test=false
> }
>
> On Wed, Apr 24, 2019 at 4:42 PM Dan Kortschak  wrote:
>
>> How would you preclude it?
>>
>> On Wed, 2019-04-24 at 16:28 -0700, lgod...@gmail.com wrote:
>> > I am NOT in favor of allowing nested ternary operations
>>
>> --
>> 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.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
>
> *Michael T. Jones michael.jo...@gmail.com *
> --
> 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.com.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Go if else syntax .. suggested replacement

2019-04-24 Thread David Koblas
IMHO I've wanted a switch expression, rather than a switch statement for 
a while.


value := switch test {
  case true => "red"
  case false => "blue"
}

or

value := switch item.(type) {
  case int => item
  case string => strconv.Atoi(item)
  case time.Time => {
    ... something more involved ... returning an int
  }
}

Sure, not as compact as ternary -- but far more powerful and useful.

On 4/24/19 9:40 PM, Michael Jones wrote:

switch test {
case true:
  //..code block for test=true
case false:
  //..code block for test=false
}

On Wed, Apr 24, 2019 at 4:42 PM Dan Kortschak > wrote:


How would you preclude it?

On Wed, 2019-04-24 at 16:28 -0700, lgod...@gmail.com
 wrote:
> I am NOT in favor of allowing nested ternary operations

-- 
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.com
.
For more options, visit https://groups.google.com/d/optout.

--
/Michael T. Jones
michael.jo...@gmail.com /
--
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.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Go if else syntax .. suggested replacement

2019-04-24 Thread Robert Engels
Wow that was some bad typing + bad auto correct...

> On Apr 24, 2019, at 9:15 PM, Robert Engels  wrote:
> 
> Your original proposal did not have the colon and also implied the {} were 
> mandatory. And what stops the sane syntax from. Ring nested ?
> 
>> On Apr 24, 2019, at 6:28 PM, lgod...@gmail.com wrote:
>> 
>> Just to clarify :  My original proposal was to include as part  of Go the 
>> syntax
>> 
>> (test) ? {
>> { //..code block for test=true
>> } : {
>>   //..code block for test=false
>> } 
>> 
>> I am NOT in favor of allowing nested ternary operations
>> 
>> In addition, I also propose allowing un-nested '?' as an alternative 
>> assignment statement i.e.  var = (temp >80) ? "red": "blue"
>> 
>> Thus, any further discussion of this topic should not involve issues related 
>> to nested ternary operations 
>> 
>>> On Tuesday, April 23, 2019 at 9:05:31 PM UTC-4, lgo...@gmail.com wrote:
>>> It sure would be nice if Go syntax allowed programmers to replace 
>>> 
>>> if ( test) {
>>> ...do sonething
>>> } else {
>>> ..do something else
>>> }
>>> 
>>> with 
>>> 
>>> ? (test) {
>>> //...do something
>>> }
>>> {
>>> //..do something else
>>> }
>>> 
>>> The ? operator can be anything the Go language team considers appropriate
>> 
>> -- 
>> 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.com.
>> For more options, visit https://groups.google.com/d/optout.

-- 
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.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Go if else syntax .. suggested replacement

2019-04-24 Thread Robert Engels
Your original proposal did not have the colon and also implied the {} were 
mandatory. And what stops the sane syntax from. Ring nested ?

> On Apr 24, 2019, at 6:28 PM, lgod...@gmail.com wrote:
> 
> Just to clarify :  My original proposal was to include as part  of Go the 
> syntax
> 
> (test) ? {
> { //..code block for test=true
> } : {
>   //..code block for test=false
> } 
> 
> I am NOT in favor of allowing nested ternary operations
> 
> In addition, I also propose allowing un-nested '?' as an alternative 
> assignment statement i.e.  var = (temp >80) ? "red": "blue"
> 
> Thus, any further discussion of this topic should not involve issues related 
> to nested ternary operations 
> 
>> On Tuesday, April 23, 2019 at 9:05:31 PM UTC-4, lgo...@gmail.com wrote:
>> It sure would be nice if Go syntax allowed programmers to replace 
>> 
>> if ( test) {
>> ...do sonething
>> } else {
>> ..do something else
>> }
>> 
>> with 
>> 
>> ? (test) {
>> //...do something
>> }
>> {
>> //..do something else
>> }
>> 
>> The ? operator can be anything the Go language team considers appropriate
> 
> -- 
> 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.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Go if else syntax .. suggested replacement

2019-04-24 Thread Dan Kortschak
I don't think that's an answer to my comment. Was it intended to be?

lgodio wrote that they wanted ternary operators, but were not
advocating that it be possible to allow nested ternary operations. I
don't see how this is possible if you write the grammar as the only
sensible interpretation

TernExpr = Expression "?" Expression ":" Expression .

Given that TernExpr would be an Expression.

The only way out of the natural possibility of having nested ternary
operator expressions would be a special case

TernExpr = NonTernExpr "?" NonTernExpr ":" NonTernExpr .

Which would then need documentation to explain it, and numerous posts here 
complaining about this weird edge case and how they should be allowed to write 
code however they want.



On Wed, 2019-04-24 at 18:40 -0700, Michael Jones wrote:
> switch test {
> case true:
>   //..code block for test=true
> case false:
>   //..code block for test=false
> }
> 
> On Wed, Apr 24, 2019 at 4:42 PM Dan Kortschak 
> wrote:
> 
> > 
> > How would you preclude it?
> > 
> > On Wed, 2019-04-24 at 16:28 -0700, lgod...@gmail.com wrote:
> > > 
> > > I am NOT in favor of allowing nested ternary operations
> > --
> > 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.com.
> > For more options, visit https://groups.google.com/d/optout.
> > 
> -- 
> 
> *Michael T. jonesmichael.jo...@gmail.com *
> 

-- 
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.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Go if else syntax .. suggested replacement

2019-04-24 Thread Michael Jones
switch test {
case true:
  //..code block for test=true
case false:
  //..code block for test=false
}

On Wed, Apr 24, 2019 at 4:42 PM Dan Kortschak  wrote:

> How would you preclude it?
>
> On Wed, 2019-04-24 at 16:28 -0700, lgod...@gmail.com wrote:
> > I am NOT in favor of allowing nested ternary operations
>
> --
> 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.com.
> For more options, visit https://groups.google.com/d/optout.
>
-- 

*Michael T. jonesmichael.jo...@gmail.com *

-- 
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.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Go if else syntax .. suggested replacement

2019-04-24 Thread Dan Kortschak
How would you preclude it?

On Wed, 2019-04-24 at 16:28 -0700, lgod...@gmail.com wrote:
> I am NOT in favor of allowing nested ternary operations

-- 
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.com.
For more options, visit https://groups.google.com/d/optout.