July 17, 2016 Re: to auto or not to auto ( in foreach ) | ||||
---|---|---|---|---|
| ||||
Posted in reply to pineapple | 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 reusing (purely cosmetical thing), but sometimes you cannot, and then `auto` is perfect candidate... but it is not allowed. (sigh)
>
> 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 be defining a new variable.
Furthermore, if foreach(int x; y) is legal then why isn't foreach(auto x; y)?
|
July 17, 2016 Re: to auto or not to auto ( in foreach ) | ||||
---|---|---|---|---|
| ||||
Posted in reply to pineapple | 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 be defining a new variable.
(x) => x; // defines a new variable
foreach isn't alone.
|
July 17, 2016 Re: to auto or not to auto ( in foreach ) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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.
|
July 18, 2016 Re: to auto or not to auto ( in foreach ) | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Saturday, 16 July 2016 at 22:05:49 UTC, ketmar wrote:
>
> `foreach (v; rng)` looks like `foreach` is *reusing* *existing* *variable*.
+1
|
July 20, 2016 Re: to auto or not to auto ( in foreach ) | ||||
---|---|---|---|---|
| ||||
Posted in reply to pineapple | 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 `immutable` or something like that there to note that it is not reusing (purely cosmetical thing), but sometimes you cannot, and then `auto` is perfect candidate... but it is not allowed. (sigh)
>>
>> 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 be defining a new variable.
>
> Furthermore, if foreach(int x; y) is legal then why isn't foreach(auto x; y)?
By the way there's an error in the grammar:
ForeachTypeAttribute:
ref
TypeCtor
But BasicType also already includes TypeCtor. So a TypeCtor in a foreach typelist is ? well hard to say, part of basic type or part of ForeachTypeAttribute ?
|
July 20, 2016 Re: to auto or not to auto ( in foreach ) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lobelia Noakes | 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 *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 cannot, and then `auto` is perfect candidate... but it is not allowed. (sigh)
>>>
>>> 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 be defining a new variable.
>>
>> Furthermore, if foreach(int x; y) is legal then why isn't foreach(auto x; y)?
>
> By the way there's an error in the grammar:
>
> ForeachTypeAttribute:
> ref
> TypeCtor
>
> But BasicType also already includes TypeCtor. So a TypeCtor in a foreach typelist is ? well hard to say, part of basic type or part of ForeachTypeAttribute ?
It's a minor issue BTW. I think that everybody that would write a D parser will skip parsing of TypeCtor in ForeachTypeAttribute and rather consider them as part of the type. I'm not sure if it can be completly removed from ForeachTypeAttribute...Does anyone know ?
|
Copyright © 1999-2021 by the D Language Foundation