Mixed int/BigInt foreach interval

Christophe travert at phare.normalesup.org
Wed Sep 28 10:03:11 PDT 2011


Timon Gehr , dans le message (digitalmars.D:145614), a écrit :
> This would probably be a breaking language change, because currently 
> '..' has no operator precedence associated with it (it is just a 
> delimiter token, much like ';').

If by breaking language change, you mean that this would break existing 
code, I don't think so. if we exclude the ugly case:..case: syntax, a..b 
can only be found between ; or ( and ), so there is no precedence issue 
if the precedence is low enough (although a too low precedence might not 
be the best place...). By the way, is there some place we can find 
operator's precedence in D?

Anyway, I guess introducing this change would imply a lot of work, that 
has no real priority. But it's worth giving it a thought.

> @Topic: In practice, I have never felt the need to use BigInt's as 
> foreach iterator variables. What is the use for such a feature?
> 
> I mean, eg. the following is hardly useful:
> 
> foreach(i;0..BigInt("10000000000000000000000000"){}

The copy on write behavior of BigInt makes it very poorly efficient 
to iterate on. In addition, I guess the compiler won't be able to 
optimize anything. Someone could say this is a good reason to make the 
.. syntax on BigInt harder to use.

-- 
Christophe


More information about the Digitalmars-d mailing list