Magnitude.st
author Stefan Vogel <sv@exept.de>
Sun, 26 Oct 2014 23:19:04 +0100
changeset 16909 d02e5b66902a
parent 16275 062c57a36882
child 18120 e3a375d5f6a8
child 18396 b42870402e9b
permissions -rw-r--r--
class: ExternalStream class definition treat ERROR_BROKEN_PIPE as EOF
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1988 by Claus Gittinger
213
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    12
"{ Package: 'stx:libbasic' }"
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    13
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    14
Object subclass:#Magnitude
1226
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    15
	instanceVariableNames:''
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    16
	classVariableNames:''
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    17
	poolDictionaries:''
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    18
	category:'Magnitude-General'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    21
!Magnitude class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    22
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    23
copyright
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    24
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    25
 COPYRIGHT (c) 1988 by Claus Gittinger
213
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
    26
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    27
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    28
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    29
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    31
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    32
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    33
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    34
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    35
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    36
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    37
documentation
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    38
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    39
    This is an abstract class definining common methods for
8181
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
    40
    Objects which can be compared by a kind of less than relation.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1226
diff changeset
    41
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1226
diff changeset
    42
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1226
diff changeset
    43
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    44
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    45
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    46
8892
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8204
diff changeset
    47
!Magnitude class methodsFor:'queries'!
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8204
diff changeset
    48
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8204
diff changeset
    49
isAbstract
11226
846103646b4a comment
Claus Gittinger <cg@exept.de>
parents: 10600
diff changeset
    50
    "Return if this class is an abstract class.
846103646b4a comment
Claus Gittinger <cg@exept.de>
parents: 10600
diff changeset
    51
     True is returned for Magnitude here; false for subclasses.
846103646b4a comment
Claus Gittinger <cg@exept.de>
parents: 10600
diff changeset
    52
     Abstract subclasses must redefine again."
846103646b4a comment
Claus Gittinger <cg@exept.de>
parents: 10600
diff changeset
    53
8892
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8204
diff changeset
    54
    ^ self == Magnitude
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8204
diff changeset
    55
! !
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8204
diff changeset
    56
10600
6bfbf469a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8892
diff changeset
    57
!Magnitude methodsFor:'Compatibility-Squeak'!
6bfbf469a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8892
diff changeset
    58
6bfbf469a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8892
diff changeset
    59
min:aMin max:aMax 
6bfbf469a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8892
diff changeset
    60
    "similar to clampBetween:and:"
6bfbf469a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8892
diff changeset
    61
6bfbf469a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8892
diff changeset
    62
    ^ (self min: aMin) max: aMax
6bfbf469a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8892
diff changeset
    63
6bfbf469a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8892
diff changeset
    64
    "Created: / 06-06-2007 / 11:00:22 / cg"
6bfbf469a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8892
diff changeset
    65
! !
6bfbf469a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8892
diff changeset
    66
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    67
!Magnitude methodsFor:'comparing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    68
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    69
< aMagnitude
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    70
    "Compare the receiver with the argument and return true if the
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    71
     receiver is less than the argument. Otherwise return false."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    72
8181
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
    73
    ^ self subclassResponsibility
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    74
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    75
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    76
<= aMagnitude
8181
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
    77
    "return true, if the argument is greater or equal than the receiver"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    78
8181
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
    79
    ^ (aMagnitude < self) not
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    80
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    81
a27a279701f8 Initial revision
claus
parents:
diff changeset
    82
= aMagnitude
a27a279701f8 Initial revision
claus
parents:
diff changeset
    83
    "Compare the receiver with the argument and return true if the
a27a279701f8 Initial revision
claus
parents:
diff changeset
    84
     receiver is equal to the argument. Otherwise return false."
a27a279701f8 Initial revision
claus
parents:
diff changeset
    85
a27a279701f8 Initial revision
claus
parents:
diff changeset
    86
    ^ self subclassResponsibility
a27a279701f8 Initial revision
claus
parents:
diff changeset
    87
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    88
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    89
> aMagnitude
8181
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
    90
    "return true, if the argument is less than the receiver"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    91
8181
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
    92
    ^ aMagnitude < self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    93
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    94
a27a279701f8 Initial revision
claus
parents:
diff changeset
    95
>= aMagnitude
8181
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
    96
    "return true, if the argument is less or equal than the receiver"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    97
8181
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
    98
    ^ (self < aMagnitude) not
213
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
    99
!
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   100
1226
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   101
clampBetween:min and:max
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   102
    "return the receiver if its between min .. max,
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   103
     or min if its less than min, or max of its greater than max.
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   104
     This is only a lazy-typers helper for: ((something min:max) max:min)"
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   105
8181
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   106
    (max < self) ifTrue:[^ max].
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   107
    (self < min) ifTrue:[^ min].
1226
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   108
    ^ self
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   109
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   110
    "
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   111
     1 clampBetween:2 and:5  
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   112
     3 clampBetween:2 and:5  
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   113
     6 clampBetween:2 and:5  
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   114
    "
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   115
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   116
    "Modified: 19.4.1996 / 14:58:12 / cg"
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   117
!
0beea7b0ab4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   118
8181
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   119
compare:arg ifLess:lessBlock ifEqual:equalBlock ifGreater:greaterBlock
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   120
    "three-way compare - thanks to Self for this idea.
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   121
     Can be redefined in subclasses to do it with a single comparison if
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   122
     comparison is expensive."
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   123
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   124
    self < arg ifTrue:[
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   125
	^ lessBlock value
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   126
    ].
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   127
    self = arg ifTrue:[
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   128
	^ equalBlock value
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   129
    ].
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   130
    ^ greaterBlock value
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   131
!
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   132
16275
062c57a36882 class: Magnitude
Stefan Vogel <sv@exept.de>
parents: 15374
diff changeset
   133
hash
062c57a36882 class: Magnitude
Stefan Vogel <sv@exept.de>
parents: 15374
diff changeset
   134
    "instances, for which #= answers true must answer the same hash"
062c57a36882 class: Magnitude
Stefan Vogel <sv@exept.de>
parents: 15374
diff changeset
   135
062c57a36882 class: Magnitude
Stefan Vogel <sv@exept.de>
parents: 15374
diff changeset
   136
    ^ self subclassResponsibility
062c57a36882 class: Magnitude
Stefan Vogel <sv@exept.de>
parents: 15374
diff changeset
   137
!
062c57a36882 class: Magnitude
Stefan Vogel <sv@exept.de>
parents: 15374
diff changeset
   138
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   139
max:aMagnitude
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   140
    "return the receiver or the argument, whichever has greater magnitude"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   141
8181
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   142
    (aMagnitude < self) ifTrue:[^ self].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   143
    ^ aMagnitude
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   144
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   145
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   146
     1 max: 2
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   147
     1 max: 2.0
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   148
     2.0 max: 1.0
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   149
     2.0 max: 2
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   150
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   151
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   152
213
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   153
min:aMagnitude
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   154
    "return the receiver or the argument, whichever has lesser magnitude"
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   155
8181
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   156
    (self < aMagnitude) ifTrue:[^ self].
213
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   157
    ^ aMagnitude
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   158
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   159
    "
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   160
     1 min: 2
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   161
     1 min: 2.0
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   162
     2.0 min: 1.0
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   163
     2.0 min: 2
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   164
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   165
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   166
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   167
!Magnitude methodsFor:'iteration'!
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   168
11602
b7c26da0a6c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11226
diff changeset
   169
downTo:stop by:step do:aBlock
b7c26da0a6c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11226
diff changeset
   170
    "For each element of the interval from the receiver down to the argument stop,
b7c26da0a6c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11226
diff changeset
   171
     decrementing by step, evaluate aBlock, passing the number as argument."
b7c26da0a6c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11226
diff changeset
   172
b7c26da0a6c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11226
diff changeset
   173
    ^ self to:stop by:step negated do:aBlock
b7c26da0a6c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11226
diff changeset
   174
b7c26da0a6c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11226
diff changeset
   175
    "
b7c26da0a6c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11226
diff changeset
   176
     10 downTo:1 by:2 do:[:i | Transcript showCR:i].
b7c26da0a6c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11226
diff changeset
   177
    "
b7c26da0a6c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11226
diff changeset
   178
!
b7c26da0a6c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11226
diff changeset
   179
6073
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   180
downTo:stop do:aBlock
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   181
    "For each element of the interval from the receiver down to the argument stop,
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   182
     evaluate aBlock, passing the number as argument."
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   183
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   184
    ^ self to:stop by:-1 do:aBlock
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   185
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   186
    "
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   187
     10 downTo:1 do:[:i | Transcript showCR:i].
8204
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   188
     $d downTo:$a do:[:i | Transcript showCR:i].
6073
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   189
    "
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   190
!
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   191
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   192
to:stop by:incr do:aBlock
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   193
    "For each element of the interval from the receiver up to the argument stop, incrementing
8204
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   194
     by step, evaluate aBlock passing the element as argument.
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   195
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   196
     Not all Magnitudes do implement #negative and #+ however, 
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   197
     so should this method go to ArithmethicValue?
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   198
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   199
     Only use #<, to speed up things (for subclasses only defining #<)"
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   200
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   201
    |tmp|
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   202
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   203
    tmp := self.
8204
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   204
"using #negative would be more portable, but stc does only inline #< but not #negative (yet)"
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   205
"/    incr negative ifTrue:[
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   206
    incr < 0 ifTrue:[
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   207
        [tmp < stop] whileFalse:[
6073
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   208
            aBlock value:tmp.
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   209
            tmp := tmp+incr
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   210
        ]
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   211
    ] ifFalse:[
8204
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   212
        [stop < tmp] whileFalse:[
6073
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   213
            aBlock value:tmp.
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   214
            tmp := tmp+incr
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   215
        ]
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   216
    ]
6073
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   217
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   218
    "
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   219
     1 to:10 do:[:i | Transcript showCR:i].
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   220
     1 to:10 by:2 do:[:i | Transcript showCR:i].
8204
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   221
     $a to:$z by:2 do:[:i | Transcript showCR:i].
6073
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   222
     10 to:1 by:-1 do:[:i | Transcript showCR:i].
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   223
    "
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   224
!
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   225
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   226
to:stop by:incr doWithBreak:aBlock
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   227
    "For each element of the interval from the receiver up to the argument stop, incrementing
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   228
     by step, evaluate aBlock passing the element as argument.
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   229
     Pass a break argument, to allow for premature exit of the loop."
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   230
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   231
    |tmp break|
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   232
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   233
    break := [^ self].
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   234
    tmp := self.
8204
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   235
"using #negative would be more portable, but stc does only inline #< but not #negative (yet)"
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   236
"/    incr negative ifTrue:[
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   237
    incr < 0 ifTrue:[
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   238
        [tmp < stop] whileFalse:[
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   239
            aBlock value:tmp value:break.
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   240
            tmp := tmp+incr
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   241
        ]
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   242
    ] ifFalse:[
8204
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   243
        [stop < tmp] whileFalse:[
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   244
            aBlock value:tmp value:break.
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   245
            tmp := tmp+incr
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   246
        ]
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   247
    ]
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   248
8204
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   249
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   250
    "
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   251
     1 to:100 by:5 doWithBreak:[:index :break |
8204
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   252
        Transcript showCR:index printString.
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   253
        index > 50 ifTrue:[
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   254
            break value
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   255
        ].
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   256
     ]
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   257
    "
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   258
!
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   259
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   260
to:stop by:incr doWithExit:aBlock
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   261
    "For each element of the interval from the receiver up to the argument stop, incrementing
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   262
     by step, evaluate aBlock passing the element as argument.
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   263
     Pass a break argument, to allow for premature exit of the loop."
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   264
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   265
    |tmp exit|
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   266
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   267
    exit := [:exitValue | ^ exitValue].
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   268
    tmp := self.
8204
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   269
"using #negative would be more portable, but stc does only inline #< but not #negative (yet)"
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   270
"/    incr negative ifTrue:[
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   271
    incr < 0 ifTrue:[
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   272
        [tmp < stop] whileFalse:[
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   273
            aBlock value:tmp value:exit.
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   274
            tmp := tmp+incr
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   275
        ]
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   276
    ] ifFalse:[
8204
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   277
        [stop < tmp] whileFalse:[
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   278
            aBlock value:tmp value:exit.
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   279
            tmp := tmp+incr
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   280
        ]
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   281
    ]
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   282
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   283
    "
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   284
     1 to:100 by:5 doWithExit:[:index :exit |
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   285
        Transcript showCR:index printString.
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   286
        index > 50 ifTrue:[
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   287
            exit value:nil
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   288
        ].
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   289
     ]
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   290
    "
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   291
!
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   292
11837
27fb4984e97b +to:count:
Claus Gittinger <cg@exept.de>
parents: 11602
diff changeset
   293
to:stop count:aBlock
27fb4984e97b +to:count:
Claus Gittinger <cg@exept.de>
parents: 11602
diff changeset
   294
    "same as (self to:stop) count:aBlock"
27fb4984e97b +to:count:
Claus Gittinger <cg@exept.de>
parents: 11602
diff changeset
   295
27fb4984e97b +to:count:
Claus Gittinger <cg@exept.de>
parents: 11602
diff changeset
   296
    |cnt|
27fb4984e97b +to:count:
Claus Gittinger <cg@exept.de>
parents: 11602
diff changeset
   297
27fb4984e97b +to:count:
Claus Gittinger <cg@exept.de>
parents: 11602
diff changeset
   298
    cnt := 0.
27fb4984e97b +to:count:
Claus Gittinger <cg@exept.de>
parents: 11602
diff changeset
   299
    self to:stop do:[:i |
27fb4984e97b +to:count:
Claus Gittinger <cg@exept.de>
parents: 11602
diff changeset
   300
       (aBlock value:i) ifTrue:[ cnt := cnt + 1 ].
27fb4984e97b +to:count:
Claus Gittinger <cg@exept.de>
parents: 11602
diff changeset
   301
    ].
27fb4984e97b +to:count:
Claus Gittinger <cg@exept.de>
parents: 11602
diff changeset
   302
    ^ cnt
27fb4984e97b +to:count:
Claus Gittinger <cg@exept.de>
parents: 11602
diff changeset
   303
27fb4984e97b +to:count:
Claus Gittinger <cg@exept.de>
parents: 11602
diff changeset
   304
    "
27fb4984e97b +to:count:
Claus Gittinger <cg@exept.de>
parents: 11602
diff changeset
   305
     1 to:10 count:[:n | n even]
27fb4984e97b +to:count:
Claus Gittinger <cg@exept.de>
parents: 11602
diff changeset
   306
    "
27fb4984e97b +to:count:
Claus Gittinger <cg@exept.de>
parents: 11602
diff changeset
   307
!
27fb4984e97b +to:count:
Claus Gittinger <cg@exept.de>
parents: 11602
diff changeset
   308
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   309
to:stop do:aBlock
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   310
    "For each element of the interval from the receiver up to the argument stop,
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   311
     evaluate aBlock, passing the number as argument."
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   312
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   313
    |tmp|
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   314
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   315
    tmp := self.
8204
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   316
    [stop < tmp] whileFalse:[
6073
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   317
        aBlock value:tmp.
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   318
        tmp := tmp+1
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   319
    ]
6073
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   320
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   321
    "
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   322
     1 to:10 do:[:i | Transcript showCR:i].
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   323
     1 to:10 by:2 do:[:i | Transcript showCR:i].
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   324
     10 to:1 by:-1 do:[:i | Transcript showCR:i].
a2b1c61dae18 added #downTo:do:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   325
    "
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   326
!
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   327
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   328
to:stop doWithBreak:aBlock
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   329
    "For each element of the interval from the receiver up to the argument stop,
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   330
     evaluate aBlock, passing the number as argument.
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   331
     Pass a break argument, to allow for premature exit of the loop."
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   332
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   333
    |tmp break|
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   334
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   335
    break := [^ self].
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   336
    tmp := self.
8204
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   337
    [stop < tmp] whileFalse:[
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   338
        aBlock value:tmp value:break.
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   339
        tmp := tmp+1
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   340
    ]
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   341
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   342
    "
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   343
     1 to:10 doWithBreak:[:index :break |
8204
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   344
        Transcript showCR:index printString.
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   345
        index > 5 ifTrue:[
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   346
            break value
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   347
        ].
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   348
     ]
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   349
    "
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   350
!
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   351
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   352
to:stop doWithExit:aBlock
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   353
    "For each element of the interval from the receiver up to the argument stop,
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   354
     evaluate aBlock, passing the number as argument.
15374
13a5c9dae49b class: Magnitude
Claus Gittinger <cg@exept.de>
parents: 11837
diff changeset
   355
     Passes an additional exit object, which can be used to leave
13a5c9dae49b class: Magnitude
Claus Gittinger <cg@exept.de>
parents: 11837
diff changeset
   356
     the loop early, by sending it a #value: message.
13a5c9dae49b class: Magnitude
Claus Gittinger <cg@exept.de>
parents: 11837
diff changeset
   357
     Returns nil or the value passed to the exit>>value: message.
13a5c9dae49b class: Magnitude
Claus Gittinger <cg@exept.de>
parents: 11837
diff changeset
   358
13a5c9dae49b class: Magnitude
Claus Gittinger <cg@exept.de>
parents: 11837
diff changeset
   359
     Notice, that this is different to a return statement in the block, 
13a5c9dae49b class: Magnitude
Claus Gittinger <cg@exept.de>
parents: 11837
diff changeset
   360
     which returns from the enclosed method, NOT only from the block."
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   361
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   362
    |exit tmp|
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   363
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   364
    exit := [:exitValue | ^exitValue].
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   365
    tmp := self.
8204
ac5db5b88079 Only use the base compare mechanism, #< for iterating
Stefan Vogel <sv@exept.de>
parents: 8181
diff changeset
   366
    [stop < tmp] whileFalse:[
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   367
        aBlock value:tmp value:exit.
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   368
        tmp := tmp+1
15374
13a5c9dae49b class: Magnitude
Claus Gittinger <cg@exept.de>
parents: 11837
diff changeset
   369
    ].
13a5c9dae49b class: Magnitude
Claus Gittinger <cg@exept.de>
parents: 11837
diff changeset
   370
    ^ nil
5565
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   371
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   372
    "
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   373
     1 to:10 doWithExit:[:index :exit |
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   374
        index == 5 ifTrue:[
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   375
            exit value:nil
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   376
        ].
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   377
        Transcript showCR:index.
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   378
     ].
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   379
    "
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   380
! !
a815d6b86ace moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   381
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   382
!Magnitude methodsFor:'testing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   383
a27a279701f8 Initial revision
claus
parents:
diff changeset
   384
between:min and:max
a27a279701f8 Initial revision
claus
parents:
diff changeset
   385
    "return whether the receiver is less than or equal to the argument max
a27a279701f8 Initial revision
claus
parents:
diff changeset
   386
     and greater than or equal to the argument min."
a27a279701f8 Initial revision
claus
parents:
diff changeset
   387
a27a279701f8 Initial revision
claus
parents:
diff changeset
   388
    (self < min) ifTrue:[^ false].
8181
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   389
    (max < self) ifTrue:[^ false].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   390
    ^ true
56
be0ed17e6f85 *** empty log message ***
claus
parents: 5
diff changeset
   391
213
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   392
    "
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   393
     1.2 between:1 and:2
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   394
     (3/2) between:1 and:2
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   395
     (3/2) between:0 and:1
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   396
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   397
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   398
a27a279701f8 Initial revision
claus
parents:
diff changeset
   399
in:anInterval
a27a279701f8 Initial revision
claus
parents:
diff changeset
   400
    "return whether the receiver is within the interval bounds"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   401
a27a279701f8 Initial revision
claus
parents:
diff changeset
   402
    (self < anInterval start) ifTrue:[^ false].
8181
b2560b88a5b1 Only use #< for comparisons, since this is the base mechanism.
Stefan Vogel <sv@exept.de>
parents: 8178
diff changeset
   403
    (anInterval stop < self)  ifTrue:[^ false].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   404
    ^ true
56
be0ed17e6f85 *** empty log message ***
claus
parents: 5
diff changeset
   405
213
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   406
    "
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   407
     1.2 in:(1 to: 2)
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   408
     (3/2) in:(1 to: 2)
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   409
     (3/2) in:(0 to: 1)
3b56a17534fd *** empty log message ***
claus
parents: 93
diff changeset
   410
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   411
! !
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   412
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   413
!Magnitude class methodsFor:'documentation'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   414
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   415
version
16275
062c57a36882 class: Magnitude
Stefan Vogel <sv@exept.de>
parents: 15374
diff changeset
   416
    ^ '$Header: /cvs/stx/stx/libbasic/Magnitude.st,v 1.27 2014-03-24 11:28:33 stefan Exp $'
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   417
! !
15374
13a5c9dae49b class: Magnitude
Claus Gittinger <cg@exept.de>
parents: 11837
diff changeset
   418