Advanced Computing Environment
Hosted by SourceForge
brix-os project page

Previous: Collections ----- Up: Contents ----- Next: Arrays


show notes
Features that need to be added to the page or ideas that haven't been thought out.
  • range of Characters? Char has the relational_interface but would also need increment and decrement operators. then range could use "T:Type of (relational_interface, increment_interface)"
  • should the range operator and type support a delta parameter?
    1..(3, 0.5) would represent (1, 1.5, 2, 2.5, 3)

The Range type represents the range of numbers between two values, inclusively. The infix .. operator simplifies the process of creating these objects.

	r1 := 1..10
	r2:Range := (1, 10)
	each 1..10 with n -> echo n;


Range of type
  • of -- required syntax when type is given
  • type -- element type (Numbers only)

constructor (first, last)






Sample Definition

	Range = deftype (`keyword of `from-constructor T:Type of Number = Number) {
	  inherit collection_interface;
	  constructor (first:T, last:T);
	  slot (first, last) = (first, last);
	  makeIterator = def (`ref r:Self, reversed:Boolean)
	    return (r, reversed) : deftype (T:Type of Range) {
	      inherit collection_iterator_interface(T.T);
	      constructor (`ref r:T, reversed:Boolean);
	      `ref slot range_object = r;
		  slot reversed = reversed;
	      slot current = if(reversed) r.last else r.first;
	      method reset()
	        self.current =
	          if(self.reversed) self.range_object.last else self.range_object.first;
	      method getCurrent() return current;
	      method moveNext()
	        if self.reversed {
	          if(self.current == self.range_object.last) throw end_of_collection;
	          return if(self.first < self.last) ++self.current else --self.current;
	        } else {
	          if(self.current == self.range_object.first) throw end_of_collection;
	          return if(self.first < self.last) --self.current else ++self.current;
	    }(typeOf r);

	// operator
	defop `common-infix .. (first:Number, last)
	  -> (first, last):Range of common

Previous: Collections ----- Up: Contents ----- Next: Arrays