Re: [go-nuts] Go could really use a while statement

2018-05-13 Thread Janne Snabb
On 2018-05-13 11:34, Hugh Fisher wrote:
> I still think a while  { ... } loop would be a worthwhile
> addition, for the reasons I've already given.

Your reason from the original post was: "I know it's possible to use a
for, but it doesn't feel right to me."

It is not reasonable to demand everyone else in the world to change to
behave according to your feelings. It is much less waste of resources
that you just learn to align your own feelings to match the world around
you.

I am sure there are also people in the world who feel that "let" would
be better than "var" and "mitähäh?" would be better than "if". Should
the language also be changed to accommodate those feelings? Obviously not.


Janne Snabb
sn...@epipe.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] Go could really use a while statement

2018-05-11 Thread Wojciech S. Czarnecki
On Fri, 11 May 2018 13:58:31 +0200
"Wojciech S. Czarnecki"  wrote:

Errata: of course body is still over condition check in
for { body; if !(condition) {break} }
construct.

https://play.golang.org/p/yHFPIYIpcfp

-- 
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] Go could really use a while statement

2018-05-11 Thread Wojciech S. Czarnecki
On Tue, 1 May 2018 04:11:03 -0700 (PDT)
Hugh Fisher  wrote:

> Another observation from this novice Go programmer: I'm puzzled why
> there's no while statement.

Because 'for' keeps condition where it belongs (at top);

If you want `do..while` as in C, Go offers more readable construct
with naked for:

n := 5
for { // do
if !(n < 10) { // do while
break
}

// body done at least once
println(n)
n++
}

Version without !(condition) adds else:

for { // do
if n < 10 { // while, 
} else {
break
}

// body done at least once
println(n)
n++
}

If you do want mix it with full fledged for, you can:

for do1, n := true, 5; n < 10 || do1; do1, n = false, n+1 {

// do body at least once
println(n)
}

Though last example is not in Go's "readability first" spirit. 

https://play.golang.org/p/8AKokpQWxkr

> Hugh Fisher
> 

-- 
Wojciech S. Czarnecki
 << ^oo^ >> OHIR-RIPE

-- 
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] Go could really use a while statement

2018-05-10 Thread Luis Furquim
I think the only real problem here is the lack of do {} while  and 
even this is not a big problem. I think we can happily live with the 
solution pointed by Sokolov, which is the one I use when needed. But 
looking at this thread what pops up is that the lacking of this construct 
at the language level opens the way to make people write the same thing in 
many different ways. So, my point is that we have 3 options: 1) change the 
language spec (in this case my vote should be for {} ); 2) use the 
Sokolov construct (in this case I suggest to include this pattern in the 
language documentation to stimulate standardization); and 3) do nothing 
about it (which is what is being done until now). 

Just my 2 cents..

Best regards

Em quinta-feira, 3 de maio de 2018 02:45:07 UTC-3, Sokolov Yura escreveu:
>
>
> for {
> Body()
> if !Condition() {
> break
> }
> }
>
> It is thats simple, guys.
>

-- 
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] Go could really use a while statement

2018-05-08 Thread 'Bryan Mills' via golang-nuts
On Thursday, May 3, 2018 at 4:25:34 AM UTC-4, rog wrote:
>
> FWIW, the thing I miss sometimes is the equivalent of C's: 
>
>  while((x = next()) != nil) { 
>  something() 
>  } 
>
> In Go you need to do either: 
>
>  for x = next(); x != nil; x = next() { 
>  something() 
>  } 
>
> which duplicates the per-iteration expression, or: 
>
>  for { 
>   x = next() 
>   if x == nil { 
>   break 
>   } 
>   something() 
>  } 
>
> which is 4 lines longer and the invariant is inverted. 
>
> A two-part for statement could potentially do that: 
>
> for x = next; x != nil { 
> something() 
> } 
>
> but it's too subtly different from the normal form to be a good language 
> change. 
>

Funny you should mention that, because I proposed a very similar change 
back in March!
(https://golang.org/issue/24282)

It's almost certainly too invasive a change on its own, but if we happen to 
decide that a breaking change is the best way to address 
https://golang.org/issue/20733, I'm hopeful that it will at least be 
considered.


On 3 May 2018 at 08:18, Dan Kortschak  > wrote: 
> > Yeah, that's not `for {} else {}`. This is spelled 
> > 
> > ``` 
> > var done bool 
> > for condition() { 
> > done = true 
> > body() 
> > } 
> > if !done { 
> > outOfBody() 
> > } 
> > ``` 
> > 
> > On Wed, 2018-05-02 at 22:45 -0700, Sokolov Yura wrote: 
> >> 
> >> for { 
> >> Body() 
> >> if !Condition() { 
> >> break 
> >> } 
> >> } 
> >> 
> >> It is thats simple, guys. 
> > 
> > -- 
> > 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...@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] Go could really use a while statement

2018-05-03 Thread Louki Sumirniy
yes I made a bunch of errors in my examples... no need for outer scope 
declaration with initialiser in the initialiser clause (one or the other, 
you know what I mean)

There is a reason why in Go an assignment statement does not also evaluate, 
but I am not aware of it, and this excludes this from the for grammar 
because the first clause is a statement not an expression, the second is an 
expression, and the third is a statement.

On Thursday, 3 May 2018 12:47:38 UTC+3, Louki Sumirniy wrote:
>
> I am writing code in which I pondered exactly using this kind of thing, it 
> involves tree walking on a binary tree, but I decided to scrap this 
> approach because, although you can't see it so clearly in that C code, it's 
> executing a function every loop that probably doesn't need to be. your 
> next() function sounds like an iterator and you could just use range 
> instead, and slices. This is most likely why this use case has been 
> rejected as it does not improve the expressive power of the statement.
>
> On Thursday, 3 May 2018 11:25:34 UTC+3, rog wrote:
>>
>> FWIW, the thing I miss sometimes is the equivalent of C's: 
>>
>>  while((x = next()) != nil) { 
>>  something() 
>>  } 
>>
>> In Go you need to do either: 
>>
>>  for x = next(); x != nil; x = next() { 
>>  something() 
>>  } 
>>
>
> I dunno if that's an error but since you are in this code above working on 
> a variable in the parent scope it would make more sense to combine the 
> declaration and initialisation outside the for block scope, as you have 
> left out a necessary var type declaration and in that case you could 
> shorten that by type inference declaring it prior to the for loop. You 
> would have a point if the declaration of x was in the first clause but even 
> then x := next() is visibly different to x=next() and alternatively even 
> you could shorten this by using indirection. For example, I would implement 
> this logic thusly:
>
> func next(x *Xtype) {}
> func first() *Xtype {  }
> ...
>
> then
>
> var x *Xtype
> for x:=first(); x!=nil; next(x) { }
>
> since after all, this next() function is semantically (human-wise) 
> ambiguous and doesn't express any relation to the nature of the list it 
> must refer to. Slices let you do this iteration even neater using range and 
> I am wondering why you can't use slices
>

-- 
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] Go could really use a while statement

2018-05-03 Thread Louki Sumirniy
I am writing code in which I pondered exactly using this kind of thing, it 
involves tree walking on a binary tree, but I decided to scrap this 
approach because, although you can't see it so clearly in that C code, it's 
executing a function every loop that probably doesn't need to be. your 
next() function sounds like an iterator and you could just use range 
instead, and slices. This is most likely why this use case has been 
rejected as it does not improve the expressive power of the statement.

On Thursday, 3 May 2018 11:25:34 UTC+3, rog wrote:
>
> FWIW, the thing I miss sometimes is the equivalent of C's: 
>
>  while((x = next()) != nil) { 
>  something() 
>  } 
>
> In Go you need to do either: 
>
>  for x = next(); x != nil; x = next() { 
>  something() 
>  } 
>

I dunno if that's an error but since you are in this code above working on 
a variable in the parent scope it would make more sense to combine the 
declaration and initialisation outside the for block scope, as you have 
left out a necessary var type declaration and in that case you could 
shorten that by type inference declaring it prior to the for loop. You 
would have a point if the declaration of x was in the first clause but even 
then x := next() is visibly different to x=next() and alternatively even 
you could shorten this by using indirection. For example, I would implement 
this logic thusly:

func next(x *Xtype) {}
func first() *Xtype {  }
...

then

var x *Xtype
for x:=first(); x!=nil; next(x) { }

since after all, this next() function is semantically (human-wise) 
ambiguous and doesn't express any relation to the nature of the list it 
must refer to. Slices let you do this iteration even neater using range and 
I am wondering why you can't use slices

-- 
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] Go could really use a while statement

2018-05-03 Thread Sokolov Yura
четверг, 3 мая 2018 г., 11:25:34 UTC+3 пользователь rog написал:
>
> FWIW, the thing I miss sometimes is the equivalent of C's: 
>
>  while((x = next()) != nil) { 
>  something() 
>  } 
>
> In Go you need to do either: 
>
>  for x = next(); x != nil; x = next() { 
>  something() 
>  } 
>
> which duplicates the per-iteration expression, or: 
>
>  for { 
>   x = next() 
>   if x == nil { 
>   break 
>   } 
>   something() 
>  } 
>
> which is 4 lines longer and the invariant is inverted. 
>
> A two-part for statement could potentially do that: 
>
> for x = next; x != nil { 
> something() 
> } 
>
> but it's too subtly different from the normal form to be a good language 
> change. 
>

Two-part for statement - that is exactly what I suggested couple years ago, 
and core-team
already rejected that.

-- 
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] Go could really use a while statement

2018-05-03 Thread roger peppe
FWIW, the thing I miss sometimes is the equivalent of C's:

 while((x = next()) != nil) {
 something()
 }

In Go you need to do either:

 for x = next(); x != nil; x = next() {
 something()
 }

which duplicates the per-iteration expression, or:

 for {
  x = next()
  if x == nil {
  break
  }
  something()
 }

which is 4 lines longer and the invariant is inverted.

A two-part for statement could potentially do that:

for x = next; x != nil {
something()
}

but it's too subtly different from the normal form to be a good language change.


On 3 May 2018 at 08:18, Dan Kortschak  wrote:
> Yeah, that's not `for {} else {}`. This is spelled
>
> ```
> var done bool
> for condition() {
> done = true
> body()
> }
> if !done {
> outOfBody()
> }
> ```
>
> On Wed, 2018-05-02 at 22:45 -0700, Sokolov Yura wrote:
>>
>> for {
>> Body()
>> if !Condition() {
>> break
>> }
>> }
>>
>> It is thats simple, guys.
>
> --
> 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] Go could really use a while statement

2018-05-03 Thread Louki Sumirniy
I just think that:

for { ... } condition()

would be a useful addition to the language because minimum one run of the 
for block is a common need.

Or to avoid any confusion, create a new reserved word:

until condition() { ... }

The lack of explicit minimum one-run in my opinion runs counter to the 
goals of Go in that it forces boilerplate like the many variations that 
have been described. Only someone who isn't fully familiar with the syntax 
of the for statement would think there is any use for a 'while' since for 
condition() {} IS a while loop.

On Thursday, 3 May 2018 10:19:39 UTC+3, kortschak wrote:
>
> Yeah, that's not `for {} else {}`. This is spelled 
>
> ``` 
> var done bool 
> for condition() { 
> done = true 
> body() 
> } 
> if !done { 
> outOfBody() 
> } 
> ``` 
>
> On Wed, 2018-05-02 at 22:45 -0700, Sokolov Yura wrote: 
> > 
> > for { 
> > Body() 
> > if !Condition() { 
> > break 
> > } 
> > } 
> > 
> > It is thats simple, guys. 
>

-- 
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] Go could really use a while statement

2018-05-03 Thread Dan Kortschak
Yeah, that's not `for {} else {}`. This is spelled

```
var done bool
for condition() {
done = true
body()
}
if !done {
outOfBody()
}
```

On Wed, 2018-05-02 at 22:45 -0700, Sokolov Yura wrote:
> 
>     for {
>     Body()
>     if !Condition() {
>     break
>     }
>     }
> 
> It is thats simple, guys.

-- 
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] Go could really use a while statement

2018-05-03 Thread Michael Jones
i code that often and comfortably.

On Wed, May 2, 2018 at 10:45 PM Sokolov Yura  wrote:

>
> for {
> Body()
> if !Condition() {
> break
> }
> }
>
> It is thats simple, guys.
>
> --
> 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.


Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread Sokolov Yura

for {
Body()
if !Condition() {
break
}
}

It is thats simple, guys.

-- 
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] Go could really use a while statement

2018-05-02 Thread Dan Kortschak
On weird proposals there's also the `for { } else { }` construct that
has been put forward before.

On Wed, 2018-05-02 at 21:06 +, Michael Jones wrote:
> Ok, weird proposal: Make the per-iteration update part of a for loop
> change
> from "assignment to assignment or boolean expression" to allow:
> 
> *while COND do {...}:*
> 
> for i:=0; x[i]<4; {...}
> 
> 
> *do {...} while COND:*
> 
> for i:= 0; ; x[i]<4 { ...}
> 
> 
> On Wed, May 2, 2018 at 12:33 PM Louki Sumirniy <
> louki.sumirniy.stal...@gmail.com> wrote:
> 
> > 
> > It adds absolutely nothing, that's why it should not be accepted.
> > It will
> > lead to a divergence in the way it's used as well. However I think
> > maybe
> > run block once before first condition check would be a useful and
> > powerful
> > addition. Maybe it shows my age that I even know what do-while
> > post-conditional loops are, and why they are useful. I have had to
> > write
> > these more wordy constructs for exactly this purpose several times
> > in a
> > project I am working on.
> > 
> > If there could be some less verbose way to flag that the condition
> > only be
> > checked first run. As I am thinking about it I am thinking of some
> > other
> > ways too, such as adding an or clause in the conditional that only
> > checks
> > if it's the first run, since golang's and and or operators are just
> > drop-throughs, well, more or less, I mean, the or operator just
> > does both
> > tests and runs the block directly if the first condition passes.
> > Here's a
> > rough sketch of it while I am thinking about it
> > 
> > for w:= true; w || ; w=false {
> >   ...
> > }
> > 
> > This will always run the first time and I can't be certain but I
> > think
> > that the compiler may skip the assignment second time since it is
> > an
> > assignment. Still wordy but it is a do-while loop, nevertheless. If
> > the
> > assignment is repeated each time it's still an overhead cost,
> > however. Some
> > kind of 'do this only once' hint to the compiler maybe. But you see
> > what I
> > mean. This is definitely a case of something Go could use as an
> > improvement
> > and if it was constructed correctly it would not break old code,
> > but
> > instead actually give people a way to improve it when refactoring
> > later on.
> > 
> > On Wednesday, 2 May 2018 20:43:11 UTC+3, Ian Lance Taylor wrote:
> > > 
> > > 
> > > On Wed, May 2, 2018 at 2:48 AM, Hugh Fisher 
> > > wrote:
> > > > 
> > > > 
> > > > On Tuesday, May 1, 2018 at 10:45:30 PM UTC+10, Ian Lance Taylor
> > > > wrote:
> > > > > 
> > > > > 
> > > > > 
> > > > > A `while` statement would presumably be exactly identical to
> > > > > a `for`
> > > > > statement with a single condition.  So adding a `while`
> > > > > statement
> > > > > would not add any power to the language, and would add an
> > > > > additional
> > > > > keyword.  All language choices are a cost benefit
> > > > > decision.  In this
> > > > > case the benefit is a looping construct that some people will
> > > > > find
> > > > > clearer to read and write, and the cost is a new keyword that
> > > > > everybody needs to learn, and that at this point in the
> > > > > language's
> > > > > evolution will likely break some, even if not much, existing
> > > > > code.  I
> > > > > don't think the benefit is worth the cost.
> > > > > 
> > > > As for not adding any power, that's why I mentioned if-then-
> > > > else and
> > > switch.
> > > > 
> > > > Switch with boolean cases is the same as if then else. It's not
> > > > an
> > > obscure
> > > > 
> > > > side effect either, the Go Tour cheerfully explains how to use
> > > > it
> > > instead of
> > > > 
> > > > if-then-else if you prefer.
> > > That is not the same thing, though.  Yes, if-then-else and switch
> > > do
> > > similar things, but they have a different syntax and are
> > > idiomatically
> > > used in different ways.  You can consider if-then-else as
> > > syntactic
> > > sugar for switch, if you like.  It's OK for a language to have
> > > some
> > > syntactic sugar.
> > > 
> > > But in this case you seem to be suggesting that we add `while
> > >  {
> > >  }` as an exact duplicate of the existing language
> > > construct
> > > `for  {  }`.  That's not syntactic sugar.  You are
> > > suggesting that `while` just be a synonym for `for`.  We don't
> > > need
> > > two different keywords that mean exactly the same thing.
> > > 
> > > 
> > > > 
> > > > Hmm, think I will have a look at the formal change proposal
> > > > process...
> > > I encourage proposals but I can tell you upfront that this
> > > proposal
> > > will not be accepted.
> > > 
> > > Ian
> > > 
> > --
> > 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
> 

Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread Michael Jones
but not this...

https://play.golang.org/p/cZnSNvi7dNU

On Wed, May 2, 2018 at 3:33 PM roger peppe  wrote:

> On 2 May 2018 at 22:06, Michael Jones  wrote:
> > Ok, weird proposal: Make the per-iteration update part of a for loop
> change
> > from "assignment to assignment or boolean expression" to allow:
> >
> > while COND do {...}:
> >
> > for i:=0; x[i]<4; {...}
> >
> >
> > do {...} while COND:
> >
> > for i:= 0; ; x[i]<4 { ...}
>
> The per-iteration part already allows arbitrary expressions (they
> might even be bool-valued)
> https://play.golang.org/p/Nt9woI7EWRP
>
> >
> > On Wed, May 2, 2018 at 12:33 PM Louki Sumirniy
> >  wrote:
> >>
> >> It adds absolutely nothing, that's why it should not be accepted. It
> will
> >> lead to a divergence in the way it's used as well. However I think
> maybe run
> >> block once before first condition check would be a useful and powerful
> >> addition. Maybe it shows my age that I even know what do-while
> >> post-conditional loops are, and why they are useful. I have had to write
> >> these more wordy constructs for exactly this purpose several times in a
> >> project I am working on.
> >>
> >> If there could be some less verbose way to flag that the condition only
> be
> >> checked first run. As I am thinking about it I am thinking of some other
> >> ways too, such as adding an or clause in the conditional that only
> checks if
> >> it's the first run, since golang's and and or operators are just
> >> drop-throughs, well, more or less, I mean, the or operator just does
> both
> >> tests and runs the block directly if the first condition passes. Here's
> a
> >> rough sketch of it while I am thinking about it
> >>
> >> for w:= true; w || ; w=false {
> >>   ...
> >> }
> >>
> >> This will always run the first time and I can't be certain but I think
> >> that the compiler may skip the assignment second time since it is an
> >> assignment. Still wordy but it is a do-while loop, nevertheless. If the
> >> assignment is repeated each time it's still an overhead cost, however.
> Some
> >> kind of 'do this only once' hint to the compiler maybe. But you see
> what I
> >> mean. This is definitely a case of something Go could use as an
> improvement
> >> and if it was constructed correctly it would not break old code, but
> instead
> >> actually give people a way to improve it when refactoring later on.
> >>
> >> On Wednesday, 2 May 2018 20:43:11 UTC+3, Ian Lance Taylor wrote:
> >>>
> >>> On Wed, May 2, 2018 at 2:48 AM, Hugh Fisher 
> wrote:
> >>> >
> >>> > On Tuesday, May 1, 2018 at 10:45:30 PM UTC+10, Ian Lance Taylor
> wrote:
> >>> >>
> >>> >>
> >>> >> A `while` statement would presumably be exactly identical to a `for`
> >>> >> statement with a single condition.  So adding a `while` statement
> >>> >> would not add any power to the language, and would add an additional
> >>> >> keyword.  All language choices are a cost benefit decision.  In this
> >>> >> case the benefit is a looping construct that some people will find
> >>> >> clearer to read and write, and the cost is a new keyword that
> >>> >> everybody needs to learn, and that at this point in the language's
> >>> >> evolution will likely break some, even if not much, existing code.
> I
> >>> >> don't think the benefit is worth the cost.
> >>> >>
> >>> > As for not adding any power, that's why I mentioned if-then-else and
> >>> > switch.
> >>> > Switch with boolean cases is the same as if then else. It's not an
> >>> > obscure
> >>> > side effect either, the Go Tour cheerfully explains how to use it
> >>> > instead of
> >>> > if-then-else if you prefer.
> >>>
> >>> That is not the same thing, though.  Yes, if-then-else and switch do
> >>> similar things, but they have a different syntax and are idiomatically
> >>> used in different ways.  You can consider if-then-else as syntactic
> >>> sugar for switch, if you like.  It's OK for a language to have some
> >>> syntactic sugar.
> >>>
> >>> But in this case you seem to be suggesting that we add `while  {
> >>>  }` as an exact duplicate of the existing language construct
> >>> `for  {  }`.  That's not syntactic sugar.  You are
> >>> suggesting that `while` just be a synonym for `for`.  We don't need
> >>> two different keywords that mean exactly the same thing.
> >>>
> >>>
> >>> > Hmm, think I will have a look at the formal change proposal
> process...
> >>>
> >>> I encourage proposals but I can tell you upfront that this proposal
> >>> will not be accepted.
> >>>
> >>> Ian
> >>
> >> --
> >> 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 

Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread roger peppe
On 2 May 2018 at 22:06, Michael Jones  wrote:
> Ok, weird proposal: Make the per-iteration update part of a for loop change
> from "assignment to assignment or boolean expression" to allow:
>
> while COND do {...}:
>
> for i:=0; x[i]<4; {...}
>
>
> do {...} while COND:
>
> for i:= 0; ; x[i]<4 { ...}

The per-iteration part already allows arbitrary expressions (they
might even be bool-valued)
https://play.golang.org/p/Nt9woI7EWRP

>
> On Wed, May 2, 2018 at 12:33 PM Louki Sumirniy
>  wrote:
>>
>> It adds absolutely nothing, that's why it should not be accepted. It will
>> lead to a divergence in the way it's used as well. However I think maybe run
>> block once before first condition check would be a useful and powerful
>> addition. Maybe it shows my age that I even know what do-while
>> post-conditional loops are, and why they are useful. I have had to write
>> these more wordy constructs for exactly this purpose several times in a
>> project I am working on.
>>
>> If there could be some less verbose way to flag that the condition only be
>> checked first run. As I am thinking about it I am thinking of some other
>> ways too, such as adding an or clause in the conditional that only checks if
>> it's the first run, since golang's and and or operators are just
>> drop-throughs, well, more or less, I mean, the or operator just does both
>> tests and runs the block directly if the first condition passes. Here's a
>> rough sketch of it while I am thinking about it
>>
>> for w:= true; w || ; w=false {
>>   ...
>> }
>>
>> This will always run the first time and I can't be certain but I think
>> that the compiler may skip the assignment second time since it is an
>> assignment. Still wordy but it is a do-while loop, nevertheless. If the
>> assignment is repeated each time it's still an overhead cost, however. Some
>> kind of 'do this only once' hint to the compiler maybe. But you see what I
>> mean. This is definitely a case of something Go could use as an improvement
>> and if it was constructed correctly it would not break old code, but instead
>> actually give people a way to improve it when refactoring later on.
>>
>> On Wednesday, 2 May 2018 20:43:11 UTC+3, Ian Lance Taylor wrote:
>>>
>>> On Wed, May 2, 2018 at 2:48 AM, Hugh Fisher  wrote:
>>> >
>>> > On Tuesday, May 1, 2018 at 10:45:30 PM UTC+10, Ian Lance Taylor wrote:
>>> >>
>>> >>
>>> >> A `while` statement would presumably be exactly identical to a `for`
>>> >> statement with a single condition.  So adding a `while` statement
>>> >> would not add any power to the language, and would add an additional
>>> >> keyword.  All language choices are a cost benefit decision.  In this
>>> >> case the benefit is a looping construct that some people will find
>>> >> clearer to read and write, and the cost is a new keyword that
>>> >> everybody needs to learn, and that at this point in the language's
>>> >> evolution will likely break some, even if not much, existing code.  I
>>> >> don't think the benefit is worth the cost.
>>> >>
>>> > As for not adding any power, that's why I mentioned if-then-else and
>>> > switch.
>>> > Switch with boolean cases is the same as if then else. It's not an
>>> > obscure
>>> > side effect either, the Go Tour cheerfully explains how to use it
>>> > instead of
>>> > if-then-else if you prefer.
>>>
>>> That is not the same thing, though.  Yes, if-then-else and switch do
>>> similar things, but they have a different syntax and are idiomatically
>>> used in different ways.  You can consider if-then-else as syntactic
>>> sugar for switch, if you like.  It's OK for a language to have some
>>> syntactic sugar.
>>>
>>> But in this case you seem to be suggesting that we add `while  {
>>>  }` as an exact duplicate of the existing language construct
>>> `for  {  }`.  That's not syntactic sugar.  You are
>>> suggesting that `while` just be a synonym for `for`.  We don't need
>>> two different keywords that mean exactly the same thing.
>>>
>>>
>>> > Hmm, think I will have a look at the formal change proposal process...
>>>
>>> I encourage proposals but I can tell you upfront that this proposal
>>> will not be accepted.
>>>
>>> Ian
>>
>> --
>> 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" 

Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread Michael Jones
Ok, weird proposal: Make the per-iteration update part of a for loop change
from "assignment to assignment or boolean expression" to allow:

*while COND do {...}:*

for i:=0; x[i]<4; {...}


*do {...} while COND:*

for i:= 0; ; x[i]<4 { ...}


On Wed, May 2, 2018 at 12:33 PM Louki Sumirniy <
louki.sumirniy.stal...@gmail.com> wrote:

> It adds absolutely nothing, that's why it should not be accepted. It will
> lead to a divergence in the way it's used as well. However I think maybe
> run block once before first condition check would be a useful and powerful
> addition. Maybe it shows my age that I even know what do-while
> post-conditional loops are, and why they are useful. I have had to write
> these more wordy constructs for exactly this purpose several times in a
> project I am working on.
>
> If there could be some less verbose way to flag that the condition only be
> checked first run. As I am thinking about it I am thinking of some other
> ways too, such as adding an or clause in the conditional that only checks
> if it's the first run, since golang's and and or operators are just
> drop-throughs, well, more or less, I mean, the or operator just does both
> tests and runs the block directly if the first condition passes. Here's a
> rough sketch of it while I am thinking about it
>
> for w:= true; w || ; w=false {
>   ...
> }
>
> This will always run the first time and I can't be certain but I think
> that the compiler may skip the assignment second time since it is an
> assignment. Still wordy but it is a do-while loop, nevertheless. If the
> assignment is repeated each time it's still an overhead cost, however. Some
> kind of 'do this only once' hint to the compiler maybe. But you see what I
> mean. This is definitely a case of something Go could use as an improvement
> and if it was constructed correctly it would not break old code, but
> instead actually give people a way to improve it when refactoring later on.
>
> On Wednesday, 2 May 2018 20:43:11 UTC+3, Ian Lance Taylor wrote:
>>
>> On Wed, May 2, 2018 at 2:48 AM, Hugh Fisher  wrote:
>> >
>> > On Tuesday, May 1, 2018 at 10:45:30 PM UTC+10, Ian Lance Taylor wrote:
>> >>
>> >>
>> >> A `while` statement would presumably be exactly identical to a `for`
>> >> statement with a single condition.  So adding a `while` statement
>> >> would not add any power to the language, and would add an additional
>> >> keyword.  All language choices are a cost benefit decision.  In this
>> >> case the benefit is a looping construct that some people will find
>> >> clearer to read and write, and the cost is a new keyword that
>> >> everybody needs to learn, and that at this point in the language's
>> >> evolution will likely break some, even if not much, existing code.  I
>> >> don't think the benefit is worth the cost.
>> >>
>> > As for not adding any power, that's why I mentioned if-then-else and
>> switch.
>> > Switch with boolean cases is the same as if then else. It's not an
>> obscure
>> > side effect either, the Go Tour cheerfully explains how to use it
>> instead of
>> > if-then-else if you prefer.
>>
>> That is not the same thing, though.  Yes, if-then-else and switch do
>> similar things, but they have a different syntax and are idiomatically
>> used in different ways.  You can consider if-then-else as syntactic
>> sugar for switch, if you like.  It's OK for a language to have some
>> syntactic sugar.
>>
>> But in this case you seem to be suggesting that we add `while  {
>>  }` as an exact duplicate of the existing language construct
>> `for  {  }`.  That's not syntactic sugar.  You are
>> suggesting that `while` just be a synonym for `for`.  We don't need
>> two different keywords that mean exactly the same thing.
>>
>>
>> > Hmm, think I will have a look at the formal change proposal process...
>>
>> I encourage proposals but I can tell you upfront that this proposal
>> will not be accepted.
>>
>> Ian
>>
> --
> 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.


Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread Louki Sumirniy
It adds absolutely nothing, that's why it should not be accepted. It will 
lead to a divergence in the way it's used as well. However I think maybe 
run block once before first condition check would be a useful and powerful 
addition. Maybe it shows my age that I even know what do-while 
post-conditional loops are, and why they are useful. I have had to write 
these more wordy constructs for exactly this purpose several times in a 
project I am working on.

If there could be some less verbose way to flag that the condition only be 
checked first run. As I am thinking about it I am thinking of some other 
ways too, such as adding an or clause in the conditional that only checks 
if it's the first run, since golang's and and or operators are just 
drop-throughs, well, more or less, I mean, the or operator just does both 
tests and runs the block directly if the first condition passes. Here's a 
rough sketch of it while I am thinking about it

for w:= true; w || ; w=false {
  ...
}

This will always run the first time and I can't be certain but I think that 
the compiler may skip the assignment second time since it is an assignment. 
Still wordy but it is a do-while loop, nevertheless. If the assignment is 
repeated each time it's still an overhead cost, however. Some kind of 'do 
this only once' hint to the compiler maybe. But you see what I mean. This 
is definitely a case of something Go could use as an improvement and if it 
was constructed correctly it would not break old code, but instead actually 
give people a way to improve it when refactoring later on.

On Wednesday, 2 May 2018 20:43:11 UTC+3, Ian Lance Taylor wrote:
>
> On Wed, May 2, 2018 at 2:48 AM, Hugh Fisher  > wrote: 
> > 
> > On Tuesday, May 1, 2018 at 10:45:30 PM UTC+10, Ian Lance Taylor wrote: 
> >> 
> >> 
> >> A `while` statement would presumably be exactly identical to a `for` 
> >> statement with a single condition.  So adding a `while` statement 
> >> would not add any power to the language, and would add an additional 
> >> keyword.  All language choices are a cost benefit decision.  In this 
> >> case the benefit is a looping construct that some people will find 
> >> clearer to read and write, and the cost is a new keyword that 
> >> everybody needs to learn, and that at this point in the language's 
> >> evolution will likely break some, even if not much, existing code.  I 
> >> don't think the benefit is worth the cost. 
> >> 
> > As for not adding any power, that's why I mentioned if-then-else and 
> switch. 
> > Switch with boolean cases is the same as if then else. It's not an 
> obscure 
> > side effect either, the Go Tour cheerfully explains how to use it 
> instead of 
> > if-then-else if you prefer. 
>
> That is not the same thing, though.  Yes, if-then-else and switch do 
> similar things, but they have a different syntax and are idiomatically 
> used in different ways.  You can consider if-then-else as syntactic 
> sugar for switch, if you like.  It's OK for a language to have some 
> syntactic sugar. 
>
> But in this case you seem to be suggesting that we add `while  { 
>  }` as an exact duplicate of the existing language construct 
> `for  {  }`.  That's not syntactic sugar.  You are 
> suggesting that `while` just be a synonym for `for`.  We don't need 
> two different keywords that mean exactly the same thing. 
>
>
> > Hmm, think I will have a look at the formal change proposal process... 
>
> I encourage proposals but I can tell you upfront that this proposal 
> will not be accepted. 
>
> Ian 
>

-- 
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] Go could really use a while statement

2018-05-02 Thread Ian Lance Taylor
On Wed, May 2, 2018 at 2:48 AM, Hugh Fisher  wrote:
>
> On Tuesday, May 1, 2018 at 10:45:30 PM UTC+10, Ian Lance Taylor wrote:
>>
>>
>> A `while` statement would presumably be exactly identical to a `for`
>> statement with a single condition.  So adding a `while` statement
>> would not add any power to the language, and would add an additional
>> keyword.  All language choices are a cost benefit decision.  In this
>> case the benefit is a looping construct that some people will find
>> clearer to read and write, and the cost is a new keyword that
>> everybody needs to learn, and that at this point in the language's
>> evolution will likely break some, even if not much, existing code.  I
>> don't think the benefit is worth the cost.
>>
> As for not adding any power, that's why I mentioned if-then-else and switch.
> Switch with boolean cases is the same as if then else. It's not an obscure
> side effect either, the Go Tour cheerfully explains how to use it instead of
> if-then-else if you prefer.

That is not the same thing, though.  Yes, if-then-else and switch do
similar things, but they have a different syntax and are idiomatically
used in different ways.  You can consider if-then-else as syntactic
sugar for switch, if you like.  It's OK for a language to have some
syntactic sugar.

But in this case you seem to be suggesting that we add `while  {
 }` as an exact duplicate of the existing language construct
`for  {  }`.  That's not syntactic sugar.  You are
suggesting that `while` just be a synonym for `for`.  We don't need
two different keywords that mean exactly the same thing.


> Hmm, think I will have a look at the formal change proposal process...

I encourage proposals but I can tell you upfront that this proposal
will not be accepted.

Ian

-- 
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] Go could really use a while statement

2018-05-02 Thread 'Axel Wagner' via golang-nuts
On Wed, May 2, 2018 at 11:48 AM Hugh Fisher  wrote:

> As for not adding any power, that's why I mentioned if-then-else and
> switch.
> Switch with boolean cases is the same as if then else. It's not an obscure
> side effect either, the Go Tour cheerfully explains how to use it instead
> of
> if-then-else if you prefer.
>

Note, that switch as a statement *does* add significant power to the
language, so this comparison is only about the statement "A missing switch
expression is equivalent to the boolean value true" from the spec - which
IMO is pretty low-impact, it doesn't add any keywords and just a pretty
simple alternation to the grammar to make a specific identifier optional.

I also think "you can replace construct A by construct B" isn't really the
same as saying "construct A does not add any power over construct B". By
that logic, loops and conditionals wouldn't really add any power to a
language, as they can be replaced by a label and a goto. And as others have
pointed out, a do-while loop *would* add some more power to the language.

What you propose, though, doesn't seem to: The simplest way to introduce
it, would be to recognize a new keyword "while" that is an alias of "for"
(and parses to the same AST). In my opinion, a simple substitution of a
keyword does not qualify for "adding power" (and I acknowledge that the
edges are fuzzy here).

It's not a new keyword to learn unless Go is your only programming language
> and you're never intending to use anything else. "while" has been a
> reserved
> word in Algol/Pascal family languages for 50 or so years, and in C/C++/Java
> family languages for over 40 years.
>
> Which is why I don't think it's going to break anyone's code. It's not a
> name
> that anyone with experience in other languages is going to use, and it's
> not
> even a natural identifier for those who've never used those other languages
> either, while being neither a noun nor verb.
>
> I did a search on go.googlesource.com/go for "while". Turned up a few C
> loops, some Python code in a string literal
> src/runtime/runtime-lldb_test.go,
> and some Emacs Lisp code in misc/emacs/go-mode.el.
>
> Not one single use of 'while' as an identifier in Go code. Nearest thing
> is a
> function scanWhile in src/encoding/json/decode.go. OK it's not all the Go
> code in existence, but I think a strong hint that Go programmers don't want
> to use while as an identifier.
>
> Hmm, think I will have a look at the formal change proposal process...
>
> cheers,
> Hugh Fisher
>
> --
> 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] Go could really use a while statement

2018-05-02 Thread Louki Sumirniy
for  { . }

is exactly a while loop. The c style for statement's second clause is exactly 
this and in c you can do this clumsily with:

for (i=1; ; true ) { . }

Go assumes that a single boolean expression is the same without initial 
statement and post block loop statement. If you want to be clever it is even 
possible to use multiple assignment operations to iterate one thing and perform 
an action on a separate thing:

fibo := 0
for i := 0; i<11 ; i, fibo = i + 1, fibo + i {}

which would produce the tenth element of the fibonacci series.

The only loop construct not possible with Go's for is the first condition to be 
evaluated after the first execution of the block.

As someone pointed out, for this the most concise construction is:

for {
  ...
  if condition {
break
  }
}

or maybe this would work:

for cond := true; cond; {
  ...
  if  {
cond = false
  }
}

but I think the first is less wordy.

If there was a language change for this, putting an optional condition after an 
unconditional for would probably break no code, eg:

for {
  ...
} 

assuming this condition is evaluated in the for block scope

-- 
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] Go could really use a while statement

2018-05-02 Thread Hugh Fisher


On Tuesday, May 1, 2018 at 10:45:30 PM UTC+10, Ian Lance Taylor wrote:
>
>
> A `while` statement would presumably be exactly identical to a `for` 
> statement with a single condition.  So adding a `while` statement 
> would not add any power to the language, and would add an additional 
> keyword.  All language choices are a cost benefit decision.  In this 
> case the benefit is a looping construct that some people will find 
> clearer to read and write, and the cost is a new keyword that 
> everybody needs to learn, and that at this point in the language's 
> evolution will likely break some, even if not much, existing code.  I 
> don't think the benefit is worth the cost. 
>
> As for not adding any power, that's why I mentioned if-then-else and 
switch.
Switch with boolean cases is the same as if then else. It's not an obscure
side effect either, the Go Tour cheerfully explains how to use it instead of
if-then-else if you prefer.

It's not a new keyword to learn unless Go is your only programming language
and you're never intending to use anything else. "while" has been a reserved
word in Algol/Pascal family languages for 50 or so years, and in C/C++/Java
family languages for over 40 years.

Which is why I don't think it's going to break anyone's code. It's not a 
name
that anyone with experience in other languages is going to use, and it's not
even a natural identifier for those who've never used those other languages
either, while being neither a noun nor verb.

I did a search on go.googlesource.com/go for "while". Turned up a few C
loops, some Python code in a string literal 
src/runtime/runtime-lldb_test.go,
and some Emacs Lisp code in misc/emacs/go-mode.el.

Not one single use of 'while' as an identifier in Go code. Nearest thing is 
a
function scanWhile in src/encoding/json/decode.go. OK it's not all the Go
code in existence, but I think a strong hint that Go programmers don't want
to use while as an identifier.

Hmm, think I will have a look at the formal change proposal process...

cheers,
Hugh Fisher

-- 
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] Go could really use a while statement

2018-05-02 Thread Jan Mercl
On Wed, May 2, 2018 at 11:34 AM Lutz Horn  wrote:

> You can even write

> for true {
> }
>
> to get an infinite loop you will have to break from.

for {
}

works just as well: https://play.golang.org/p/aEkbUjLmf_T

-- 

-j

-- 
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.


AW: [go-nuts] Go could really use a while statement

2018-05-02 Thread Lutz Horn
> No, I meant a while  { ... } loop

for foo > 1 {
}

is exactly what you are looking for. You can even write

for true {
}

to get an infinite loop you will have to break from.

-- 
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] Go could really use a while statement

2018-05-02 Thread Hugh Fisher


On Tuesday, May 1, 2018 at 11:57:13 PM UTC+10, Michael Jones wrote:
>
> Maybe he meant "until" aka "do {...} while cond" -- this is a valuable and 
> missing mechanism. The argument back in the day was that having just one 
> looping construct was more friendly to tooling. 
>
>
No, I meant a while  { ... } loop

cheers,
Hugh Fisher
 

-- 
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] Go could really use a while statement

2018-05-01 Thread Justin Israel
On Wed, May 2, 2018, 1:56 AM Michael Jones  wrote:

> Maybe he meant "until" aka "do {...} while cond" -- this is a valuable and
> missing mechanism. The argument back in the day was that having just one
> looping construct was more friendly to tooling.
>

Based on this...

> I know it's possible to use a for, but it doesn't feel right to me. I
always
think of for loops as for iterating over data structures.

... I didn't think it meant a different construct like 'do while'.

It just comes down to how one thinks of for loops. To me, even though I
come from a Python background with a 'while' construct, I don't think of a
for loop in Go as specifically iterating over data structures. I think of
it as looping for the duration of a True condition. So that being said I
could see this being the same:

while item := range items {...}



> On Tue, May 1, 2018 at 5:45 AM Ian Lance Taylor  wrote:
>
>> On Tue, May 1, 2018 at 4:11 AM, Hugh Fisher 
>> wrote:
>> >
>> > Another observation from this novice Go programmer: I'm puzzled why
>> > there's no while statement.
>> >
>> > I know it's possible to use a for, but it doesn't feel right to me. I
>> always
>> > think of for loops as for iterating over data structures. Originally
>> just
>> > arrays, but languages like Python and Objective-C have extended for
>> > loops to other collections as well. "Looping until some condition is
>> met"
>> > for me is a different control structure and needs a different keyword.
>> >
>> > There'd be overlap with the for statement, but if-then-else and switch
>> > with boolean case overlap too.
>> >
>> > And since while has been a reserved keyword in a lot of programming
>> > languages for many decades, I would bet a reasonable amount of
>> > money that a while statement could be added to Go right now and not
>> > break anyone's production code.
>>
>> A `while` statement would presumably be exactly identical to a `for`
>> statement with a single condition.  So adding a `while` statement
>> would not add any power to the language, and would add an additional
>> keyword.  All language choices are a cost benefit decision.  In this
>> case the benefit is a looping construct that some people will find
>> clearer to read and write, and the cost is a new keyword that
>> everybody needs to learn, and that at this point in the language's
>> evolution will likely break some, even if not much, existing code.  I
>> don't think the benefit is worth the cost.
>>
>> Ian
>>
>> --
>> 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] Go could really use a while statement

2018-05-01 Thread xiofen77


>
> On Tue, May 1, 2018 at 7:36 AM Alisdair  > wrote:
>
>> Isn't `for { ... if cond { break; } }` the same as `do {...} while cond`? 
>> Whilst having the benefits of not adding new keywords and maintaining the 
>> logic of the loop entirely within the block of the loop making it simpler 
>> to understand.
>>
>>
>>
Doesn't that check at initialization of the loop, while a "repeat until/do 
while" checks after at least one pass.. ? 

-- 
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] Go could really use a while statement

2018-05-01 Thread Alisdair
Isn't `for { ... if cond { break; } }` the same as `do {...} while cond`?
Whilst having the benefits of not adding new keywords and maintaining the
logic of the loop entirely within the block of the loop making it simpler
to understand.

On Tue, 1 May 2018 at 14:56, Michael Jones  wrote:

> Maybe he meant "until" aka "do {...} while cond" -- this is a valuable and
> missing mechanism. The argument back in the day was that having just one
> looping construct was more friendly to tooling.
>
> On Tue, May 1, 2018 at 5:45 AM Ian Lance Taylor  wrote:
>
>> On Tue, May 1, 2018 at 4:11 AM, Hugh Fisher 
>> wrote:
>> >
>> > Another observation from this novice Go programmer: I'm puzzled why
>> > there's no while statement.
>> >
>> > I know it's possible to use a for, but it doesn't feel right to me. I
>> always
>> > think of for loops as for iterating over data structures. Originally
>> just
>> > arrays, but languages like Python and Objective-C have extended for
>> > loops to other collections as well. "Looping until some condition is
>> met"
>> > for me is a different control structure and needs a different keyword.
>> >
>> > There'd be overlap with the for statement, but if-then-else and switch
>> > with boolean case overlap too.
>> >
>> > And since while has been a reserved keyword in a lot of programming
>> > languages for many decades, I would bet a reasonable amount of
>> > money that a while statement could be added to Go right now and not
>> > break anyone's production code.
>>
>> A `while` statement would presumably be exactly identical to a `for`
>> statement with a single condition.  So adding a `while` statement
>> would not add any power to the language, and would add an additional
>> keyword.  All language choices are a cost benefit decision.  In this
>> case the benefit is a looping construct that some people will find
>> clearer to read and write, and the cost is a new keyword that
>> everybody needs to learn, and that at this point in the language's
>> evolution will likely break some, even if not much, existing code.  I
>> don't think the benefit is worth the cost.
>>
>> Ian
>>
>> --
>> 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] Go could really use a while statement

2018-05-01 Thread Michael Jones
Correct.

On Tue, May 1, 2018 at 7:36 AM Alisdair 
wrote:

> Isn't `for { ... if cond { break; } }` the same as `do {...} while cond`?
> Whilst having the benefits of not adding new keywords and maintaining the
> logic of the loop entirely within the block of the loop making it simpler
> to understand.
>
> On Tue, 1 May 2018 at 14:56, Michael Jones 
> wrote:
>
>> Maybe he meant "until" aka "do {...} while cond" -- this is a valuable
>> and missing mechanism. The argument back in the day was that having just
>> one looping construct was more friendly to tooling.
>>
>> On Tue, May 1, 2018 at 5:45 AM Ian Lance Taylor  wrote:
>>
>>> On Tue, May 1, 2018 at 4:11 AM, Hugh Fisher 
>>> wrote:
>>> >
>>> > Another observation from this novice Go programmer: I'm puzzled why
>>> > there's no while statement.
>>> >
>>> > I know it's possible to use a for, but it doesn't feel right to me. I
>>> always
>>> > think of for loops as for iterating over data structures. Originally
>>> just
>>> > arrays, but languages like Python and Objective-C have extended for
>>> > loops to other collections as well. "Looping until some condition is
>>> met"
>>> > for me is a different control structure and needs a different keyword.
>>> >
>>> > There'd be overlap with the for statement, but if-then-else and switch
>>> > with boolean case overlap too.
>>> >
>>> > And since while has been a reserved keyword in a lot of programming
>>> > languages for many decades, I would bet a reasonable amount of
>>> > money that a while statement could be added to Go right now and not
>>> > break anyone's production code.
>>>
>>> A `while` statement would presumably be exactly identical to a `for`
>>> statement with a single condition.  So adding a `while` statement
>>> would not add any power to the language, and would add an additional
>>> keyword.  All language choices are a cost benefit decision.  In this
>>> case the benefit is a looping construct that some people will find
>>> clearer to read and write, and the cost is a new keyword that
>>> everybody needs to learn, and that at this point in the language's
>>> evolution will likely break some, even if not much, existing code.  I
>>> don't think the benefit is worth the cost.
>>>
>>> Ian
>>>
>>> --
>>> 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.
>>
>

-- 
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.


Re: [go-nuts] Go could really use a while statement

2018-05-01 Thread Michael Jones
Maybe he meant "until" aka "do {...} while cond" -- this is a valuable and
missing mechanism. The argument back in the day was that having just one
looping construct was more friendly to tooling.

On Tue, May 1, 2018 at 5:45 AM Ian Lance Taylor  wrote:

> On Tue, May 1, 2018 at 4:11 AM, Hugh Fisher  wrote:
> >
> > Another observation from this novice Go programmer: I'm puzzled why
> > there's no while statement.
> >
> > I know it's possible to use a for, but it doesn't feel right to me. I
> always
> > think of for loops as for iterating over data structures. Originally just
> > arrays, but languages like Python and Objective-C have extended for
> > loops to other collections as well. "Looping until some condition is met"
> > for me is a different control structure and needs a different keyword.
> >
> > There'd be overlap with the for statement, but if-then-else and switch
> > with boolean case overlap too.
> >
> > And since while has been a reserved keyword in a lot of programming
> > languages for many decades, I would bet a reasonable amount of
> > money that a while statement could be added to Go right now and not
> > break anyone's production code.
>
> A `while` statement would presumably be exactly identical to a `for`
> statement with a single condition.  So adding a `while` statement
> would not add any power to the language, and would add an additional
> keyword.  All language choices are a cost benefit decision.  In this
> case the benefit is a looping construct that some people will find
> clearer to read and write, and the cost is a new keyword that
> everybody needs to learn, and that at this point in the language's
> evolution will likely break some, even if not much, existing code.  I
> don't think the benefit is worth the cost.
>
> Ian
>
> --
> 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.


Re: [go-nuts] Go could really use a while statement

2018-05-01 Thread Ian Lance Taylor
On Tue, May 1, 2018 at 4:11 AM, Hugh Fisher  wrote:
>
> Another observation from this novice Go programmer: I'm puzzled why
> there's no while statement.
>
> I know it's possible to use a for, but it doesn't feel right to me. I always
> think of for loops as for iterating over data structures. Originally just
> arrays, but languages like Python and Objective-C have extended for
> loops to other collections as well. "Looping until some condition is met"
> for me is a different control structure and needs a different keyword.
>
> There'd be overlap with the for statement, but if-then-else and switch
> with boolean case overlap too.
>
> And since while has been a reserved keyword in a lot of programming
> languages for many decades, I would bet a reasonable amount of
> money that a while statement could be added to Go right now and not
> break anyone's production code.

A `while` statement would presumably be exactly identical to a `for`
statement with a single condition.  So adding a `while` statement
would not add any power to the language, and would add an additional
keyword.  All language choices are a cost benefit decision.  In this
case the benefit is a looping construct that some people will find
clearer to read and write, and the cost is a new keyword that
everybody needs to learn, and that at this point in the language's
evolution will likely break some, even if not much, existing code.  I
don't think the benefit is worth the cost.

Ian

-- 
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.


[go-nuts] Go could really use a while statement

2018-05-01 Thread Hugh Fisher

Another observation from this novice Go programmer: I'm puzzled why
there's no while statement.

I know it's possible to use a for, but it doesn't feel right to me. I always
think of for loops as for iterating over data structures. Originally just
arrays, but languages like Python and Objective-C have extended for
loops to other collections as well. "Looping until some condition is met"
for me is a different control structure and needs a different keyword.

There'd be overlap with the for statement, but if-then-else and switch
with boolean case overlap too.

And since while has been a reserved keyword in a lot of programming
languages for many decades, I would bet a reasonable amount of
money that a while statement could be added to Go right now and not
break anyone's production code.

cheers,
Hugh Fisher

-- 
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.