Foreach Range Statement
Bill Baxter
dnewsgroup at billbaxter.com
Mon Jul 23 14:02:22 PDT 2007
Sean Kelly wrote:
> Reiner Pope wrote:
>> Bill Baxter wrote:
>>> Don Clugston wrote:
>>>> I think the convention "first_element .. last_element+1" cannot be
>>>> extended to negative and floating-point numbers without creating an
>>>> inconsistency. Which is quite unfortunate.
>>
>> I'm not sure of the problem with negative integers is. Even for
>> negative integers x, the identity still holds, that the following two
>> expressions are equivalent:
>>
>> a <= x
>> a < x+1
>>
>> But the floating point issue is a bummer. And it's also a bit silly
>> for chars. To test whether c is a digit, you would have to write:
>>
>> c in ['0'..'9'+1]
>>
>> which looks a little silly.
>
> Perhaps there should be an operator for inclusive vs. exclusive ranges.
> Something like:
>
> c in ['0' -> '9']
>
> Not ideal, I know.
>
>
> Sean
In previous discussion it was mentioned that Ruby has a..b and a...b as
inclusive and exclusive ranges, respectively. The previous thread also
threw around a lot of possible alternative syntaxes.
--bb
More information about the Digitalmars-d
mailing list