30 Mar 2005 17:06
Re: thoughts about the Range concept
On 30 Mar 2005, at 10:20, Dierk Koenig wrote: > Ok, I think I got it. > Thanx for your patient explanations. > > To sum up my misconceptions: > a) Ranges are not intervals > (maybe we introduce an Interval concept later?) They are implemented as such - as immutable intervals - though we currently have 2 implementations; IntRange for efficient integer ranges (which are really common) and ObjectRange (which are less so) but work with any Object which is comparable. > b) contains() and isCase() ( and thus filtering with > grep and classification with switch) do not apply > compareTo() to the bounds but check for element containment > in the backing list. The is no backing list; the contains method works on range checking based on the upper/lower bounds > c) lowerBound <= a <= upperBound does _not_ imply > (lowerBound..upperBound).contains(a) It does currently at least > d) plus() is not closed under Ranges but returns a List Any method on Range/List which returns a new List, will return a real list. So adding/creating subList() mostly right now will create a new, mutable List. Though the Range itself is immutable. > effect: > - Ranges cannot be used like in Ruby (where === is Ruby's > version of Groovy's isCase()) > C:\Documents and Settings\dierk>irb > irb(main):001:0> (0.0..1.0)===(0.99) > => true Why? That should work in Groovy when using the ObjectRange; provided the upper & lower bound objects compare with the element you're performing the comparison with. > My personal opinion: > a) is counter-intuitive > b) restricts applicability of Ranges for classification to IntRanges There's ObjectRange too James ------- http://radio.weblogs.com/0112098/
RSS Feed