jastrachan | 12 Apr 09:59 2005
Picon

Re: [groovy-dev] 0..<0 not empty

So how about if we made the following changes...

* ranges start with a lower value and finish with the higher value.  So 
0..-1 and 0..<-1 is an empty range - avoiding those nasty surprises 
folks have mentioned
* to perform reverse iteration, we use a reverse() method
* we support stepping of ranges via Range.step(value) which could 
create a new range implementation (StepRange) which adds a step value 
to the fromValue until its greater or equal to the toValue.

On a side note I confess to liking the use of negative indexes to count 
from the end of a collection/array/string. e.g. to get the last element 
of a list/array its

     list[-1]
     array[-1]

This won't conflict with the range changes above since negative numbers 
mean nothing to a range.

On 11 Apr 2005, at 13:08, Wang Bin wrote:
> I bet it is a serious bug. It should act as "abc".substring(0,0)! If 
> not so, we all will be confused by it.
>
> ----- Original Message -----
> From: "Dierk Koenig" <dierk.koenig@...>
> To: <dev@...>
> Sent: Monday, April 11, 2005 5:25 AM
> Subject: [groovy-dev] 0..<0 not empty
>
>
>> Hi,
>>
>> log = ''
>> for (element in 0..<0){
>>     log += element
>> }
>> assert log == ''
>>
>> produces
>>
>> Caught: java.lang.AssertionError: Expression: (log == ). Values: log 
>> = 0-1
>>
>> cheers
>> Mittie
>>
>>

James
-------
http://radio.weblogs.com/0112098/


Gmane