--- a/Interval.st Thu Jun 25 06:36:01 2015 +0200
+++ b/Interval.st Fri Jun 26 06:36:52 2015 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
@@ -11,6 +13,8 @@
"
"{ Package: 'stx:libbasic' }"
+"{ NameSpace: Smalltalk }"
+
ReadOnlySequenceableCollection subclass:#Interval
instanceVariableNames:'start stop step'
classVariableNames:''
@@ -44,6 +48,10 @@
For example, the interval (1 to:5) containes the elements (1 2 3 4 5) and
(1 to:6 by:2) contains (1 3 5).
+ The step may be negative, to count backward:
+ (5 to:1 by:-1) contains (5 4 3 2 1), and (6 to:1 by:-2) contains (6 4 2).
+
+
examples:
(1 to:10) do:[:i | Transcript showCR:i]
@@ -535,12 +543,12 @@
(start < stop) ifTrue:[
^ 0
].
- ^ stop - start // step + 1
+ ^ (start - stop) // step abs + 1
].
(stop < start) ifTrue:[
^ 0
].
- ^ stop - start // step + 1
+ ^ (stop - start) // step + 1
! !
!Interval methodsFor:'set operations'!
@@ -690,10 +698,10 @@
!Interval class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Interval.st,v 1.57 2014-07-10 12:23:57 cg Exp $'
+ ^ '$Header$'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/Interval.st,v 1.57 2014-07-10 12:23:57 cg Exp $'
+ ^ '$Header$'
! !