Code behaves incorrectly if it is compiled in std.functional

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 8 08:14:18 PDT 2015


On Mon, 08 Jun 2015 15:54:23 +0200, Timon Gehr wrote:

> On 06/08/2015 03:17 PM, ketmar wrote:
>> ...
>>
>> i tried to explain to some people why `foreach (i; 0..42)` doesn't
>> reuse previously declared `i` and failed.
> 
> The reason is that it wouldn't make any sense.
> 
>> it doesn't look like variable declaration at all,
> 
> It looks like a variable declaration because it is a variable
> declaration. It declares the foreach loop variable.

no. it looks like "let's use our previously declared `i` as a counter". 
there is no single sign of variable declaration here. like `while (i)` 
will not declare a new variable, or `foo(i, n)`, or `if (i)`.

>> and there is no way to make it look like variable declaration without
>> specifying a type or `const/immutable/etc.`. so "default storage class"
>> doesn't make sense in `foreach`?
> 
> I didn't make the decision, but it is redundant.

only if D doesn't meant to be a language which is easily readable by 
humans. declaring new variable by simply specifying it's name isn't used 
anywhere else. oh, well, another exception to remember. another good step 
to success. the more exceptions, the more steps...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150608/4f8137ca/attachment.sig>


More information about the Digitalmars-d mailing list