Am 09.02.2011 19:54, schrieb bearophile: > > - Both 1..5 and iota(1,5) are able to support the "in" operator. This is good > because D doesn't support the a<X<b Python syntax. X in a..b will mean > a<=X<b. >
Don't know about Python, but in D this will only be true if X is an integer. I guess 1<X<4 is true for X=1.5 in Python.. it would certainly not be true for X in 1..4 in D. Also using X in 1..4 is in D is pretty bad if you just want to check if 1<X<4 (or even more when checking 1<X<100) because it has a much higher overhead - even though it may be technically O(1) because 4 or 100 is a constant) than just doing two comparisons. So IMHO using X in 1..4 or x in iota(1,4) should not be encouraged. (X in [1,3,4,8] is different.) Of course the compiler could transform X in 1..4 to X>1 && X<4, but... I don't think it's a good idea. If this syntax is accepted, 1..4 should create a range/array containing [1,2,3] - without addidional voodoo. > - If the compiler front-end becomes aware of the interval syntax, it is able > to perform "3 in 1..10" at compile-time too, simplifying sub-expressions even > when they are inside other run-time expressions. > Cheers, - Daniel
