Mixed int/BigInt foreach interval
kennytm
kennytm at gmail.com
Tue Sep 27 14:30:22 PDT 2011
"Jonathan M Davis" <jmdavisProg at gmx.com> wrote:
> On Tuesday, September 27, 2011 12:22 bearophile wrote:
>> Jonathan M Davis:
>>>> foreach (i; 1 .. BigInt(10)) {}
>>>
>>> No. That's foreach. BigInt isn't going to work with the .. syntax
>>> regardless of what isIntegral does. I assume what you're really asking
>>> is whether
>>
>> I'm asking about foreach, not about iota. Fixing iota is easy, it's just a
>> matter of changing Phobos.
>>
>> This is why at the top of my original post I have written:
>>> In my opinion it's important to make BigInts work in most places where
>>> normal ints work. I think it's even worth modifying D language a bit (if
>>> and where necessary) to allow this.
>>
>> The point of my post was to talk about foreach. The title of this thread is
>> "Mixed int/BigInt foreach interval".
>
> I'd be _very_ surprised to see that happen, since BigInt is in Phobos as
> opposed to being at the language level. Ranges could be added to foreach,
> because they're entirely API-based, and so the compiler doesn't have to care
> about what Phobos is doing. It just has to do the appropriate lowerings. But
> BigInt is a specific type in Phobos. Making it work with foreach would mean
> that the compiler would have to know and understand about BigInt. I don't
> expect that to ever happen. Best case, I would think that you could get it to
> work by having BigInt be implicitly convertible to int, but since that's a
> narrowing conversion, that's a _bad_ idea IMHO.
>
> - Jonathan M Davis
foreach (a; b .. c) d; is also a lowering, and i'd say the 'int + BigInt'
not able to typeCombine (statement.c:2282) a bug.
By the way, the statement
foreach (a; BigInt(1) .. 10) ...
does compile and work, at least for the toolset from git master.
More information about the Digitalmars-d
mailing list