foreach/iota countdown

simendsjo simendsjo at gmail.com
Mon Feb 17 13:12:31 PST 2014


On Monday, 17 February 2014 at 21:06:50 UTC, Timon Gehr wrote:
> On 02/17/2014 09:21 PM, simendsjo wrote:
>> On Monday, 17 February 2014 at 20:03:32 UTC, Timon Gehr wrote:
>>> ...
>>>
>>> It was just to illustrate the issue more clearly. Eg. it 
>>> means one and
>>> the same iota expression can sometimes iterate in one 
>>> direction and in
>>> the other direction at other times. That's simply not useful 
>>> behaviour.
>>
>> I'm not sure what I find more confusing. Ok if it's a 
>> deliberate choice
>> never to change the step direction, but is it deliberate that 
>> it's not
>> an error to have a greater lower bound than upper bound? Or is 
>> this just
>> the way it happened to be implemented?
>
> That's deliberate. I don't really understand how it is 
> confusing.
>
> To draw an analogy, given (low ∈ ℕ)  and (high ∈ ℕ),
>
> { x ∈ ℕ | low ≤ x ∧ x < high }
>
> is just the empty set if low > high. It is not illegal or 
> unusual.

Ok, I yield. I just happened to write
   foreach(i; 10 .. 0)
and was suprised that it didn't give any warnings or errors.

But I still somewhat stand by my point: Dead code is illegal in 
D, and this is code that will never run, hence dead code.


More information about the Digitalmars-d-learn mailing list