Re: to auto or not to auto ( in foreach )

2016-07-20 Thread Lobelia Noakes via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 15:40:16 UTC, Lobelia Noakes wrote: On Sunday, 17 July 2016 at 01:58:59 UTC, pineapple wrote: On Sunday, 17 July 2016 at 01:57:21 UTC, pineapple wrote: On Saturday, 16 July 2016 at 22:05:49 UTC, ketmar wrote: actually, `foreach (v; rng)` looks like `foreach` is

Re: to auto or not to auto ( in foreach )

2016-07-20 Thread Lobelia Noakes via Digitalmars-d-learn
On Sunday, 17 July 2016 at 01:58:59 UTC, pineapple wrote: On Sunday, 17 July 2016 at 01:57:21 UTC, pineapple wrote: On Saturday, 16 July 2016 at 22:05:49 UTC, ketmar wrote: actually, `foreach (v; rng)` looks like `foreach` is *reusing* *existing* *variable*. most of the time you can put

Re: to auto or not to auto ( in foreach )

2016-07-18 Thread Johan Engelen via Digitalmars-d-learn
On Saturday, 16 July 2016 at 22:05:49 UTC, ketmar wrote: `foreach (v; rng)` looks like `foreach` is *reusing* *existing* *variable*. +1

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread ketmar via Digitalmars-d-learn
On Sunday, 17 July 2016 at 02:04:50 UTC, Adam D. Ruppe wrote: (x) => x; // defines a new variable foreach isn't alone. compiler should allow `auto` here too.

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 17 July 2016 at 01:57:21 UTC, pineapple wrote: Chipping in my agreement. foreach(x; y) makes as much syntactic sense as for(x = 0; x < y; x++) where x was not previously defined. One does not expect something that does not look like every other variable definition in the language to

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread pineapple via Digitalmars-d-learn
On Sunday, 17 July 2016 at 01:57:21 UTC, pineapple wrote: On Saturday, 16 July 2016 at 22:05:49 UTC, ketmar wrote: actually, `foreach (v; rng)` looks like `foreach` is *reusing* *existing* *variable*. most of the time you can put `immutable` or something like that there to note that it is not

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread pineapple via Digitalmars-d-learn
On Saturday, 16 July 2016 at 22:05:49 UTC, ketmar wrote: actually, `foreach (v; rng)` looks like `foreach` is *reusing* *existing* *variable*. most of the time you can put `immutable` or something like that there to note that it is not reusing (purely cosmetical thing), but sometimes you

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread ketmar via Digitalmars-d-learn
On Saturday, 16 July 2016 at 21:39:42 UTC, cym13 wrote: However auto should be allowed here. You are defining a variable and the fact that it's in a foreach shouldn't be of any importance. The language should enforce orthogonality of orthogonal things, not break it. A variable definition in a

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread cym13 via Digitalmars-d-learn
On Saturday, 16 July 2016 at 21:39:42 UTC, cym13 wrote: A variable definition in a foreach -> A variable definition *with auto* in a foreach

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread cym13 via Digitalmars-d-learn
On Saturday, 16 July 2016 at 20:00:39 UTC, Seb wrote: On Saturday, 16 July 2016 at 14:11:34 UTC, cym13 wrote: On Saturday, 16 July 2016 at 14:00:56 UTC, dom wrote: foreach(auto v; msg) writeln(v); gives an error that a basic type is expected foreach(v; msg) writeln(v); works .. but

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread Seb via Digitalmars-d-learn
On Saturday, 16 July 2016 at 20:00:39 UTC, Seb wrote: On Saturday, 16 July 2016 at 14:11:34 UTC, cym13 wrote: [...] It's not arbitrary. It keeps the language simple and easy to read. After all the entire auto keyword is just there, because the compiler needs a keyword and in loops it's

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread Seb via Digitalmars-d-learn
On Saturday, 16 July 2016 at 14:11:34 UTC, cym13 wrote: On Saturday, 16 July 2016 at 14:00:56 UTC, dom wrote: foreach(auto v; msg) writeln(v); gives an error that a basic type is expected foreach(v; msg) writeln(v); works .. but why? Arbitrary limitation. If you want to say how

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread ketmar via Digitalmars-d-learn
On Saturday, 16 July 2016 at 14:00:56 UTC, dom wrote: .. but why? because. i've lost that fight too.

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread cym13 via Digitalmars-d-learn
On Saturday, 16 July 2016 at 14:00:56 UTC, dom wrote: foreach(auto v; msg) writeln(v); gives an error that a basic type is expected foreach(v; msg) writeln(v); works .. but why? Arbitrary limitation. If you want to say how surprising and uselessly limiting it is wait at the end of the

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 16 July 2016 at 14:00:56 UTC, dom wrote: foreach(auto v; msg) writeln(v); gives an error that a basic type is expected foreach(v; msg) writeln(v); works .. but why? `Note: The ForeachTypeAttribute is implicit, and when a type is not specified, it is inferred. In that