| Thread overview | |||||||||
|---|---|---|---|---|---|---|---|---|---|
|
March 01, 2013 Different loops bug | ||||
|---|---|---|---|---|
| ||||
This is derived from part of a D.learn post, maybe it's of your interest.
This program shows two similar versions of the same loop:
import std.stdio, std.algorithm, std.typetuple, std.range;
void main() {
auto items = [[10, 20], [30]];
foreach (_; 0 .. 2) {
foreach (sub; items) {
iota(sub.length)
.map!((i){ writeln(sub); return 0; })
.array();
}
}
writeln();
foreach (_; TypeTuple!(0, 1)) {
foreach (sub; items) {
iota(sub.length)
.map!((i){ writeln(sub); return 0; })
.array();
}
}
}
Its output:
[10, 20]
[10, 20]
[30]
[10, 20]
[10, 20]
[30]
[10, 20]
[10, 20]
[30]
[30]
[30]
[30]
Do you see why the output of the two foreach(_) is different?
Bye,
bearophile
| ||||
March 01, 2013 Re: Different loops bug | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 03/01/2013 11:07 PM, bearophile wrote:
> ...
>
> Do you see why the output of the two foreach(_) is different?
>
They are not different.
| |||
March 01, 2013 Re: Different loops bug | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | Timon Gehr:
> They are not different.
Really? Sorry, I don't understand.
Bye,
bearophile
| |||
March 01, 2013 Re: Different loops bug | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 03/02/2013 12:23 AM, bearophile wrote:
> Timon Gehr:
>
>> They are not different.
>
> Really? Sorry, I don't understand.
>
> Bye,
> bearophile
According to the spec the two outputs are the same.
| |||
March 02, 2013 Re: Different loops bug | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On Friday, 1 March 2013 at 23:25:31 UTC, Timon Gehr wrote:
> On 03/02/2013 12:23 AM, bearophile wrote:
>> Timon Gehr:
>>
>>> They are not different.
>>
>> Really? Sorry, I don't understand.
>>
>> Bye,
>> bearophile
>
> According to the spec the two outputs are the same.
Are you saying they should output the same or that they are the same?
You and I have a different definition of "same" if the latter.
| |||
March 02, 2013 Re: Different loops bug | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | Timon Gehr: > According to the spec the two outputs are the same. I have filed this: http://d.puremagic.com/issues/show_bug.cgi?id=9628 Bye, bearophile | |||
March 02, 2013 Re: Different loops bug | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Brad Anderson | On 03/02/2013 01:17 AM, Brad Anderson wrote:
> On Friday, 1 March 2013 at 23:25:31 UTC, Timon Gehr wrote:
>> On 03/02/2013 12:23 AM, bearophile wrote:
>>> Timon Gehr:
>>>
>>>> They are not different.
>>>
>>> Really? Sorry, I don't understand.
>>>
>>> Bye,
>>> bearophile
>>
>> According to the spec the two outputs are the same.
>
> Are you saying they should output the same or that they are the same?
>
> You and I have a different definition of "same" if the latter.
With a correct implementation of the language, the outputs are the same. Bugs should go to the bug tracker.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply