1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
384
|
3 |
All Rights Reserved
|
1
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
6906
|
12 |
"{ Package: 'stx:libbasic' }"
|
|
13 |
|
1
|
14 |
Boolean subclass:#True
|
1238
|
15 |
instanceVariableNames:''
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Kernel-Objects'
|
1
|
19 |
!
|
|
20 |
|
88
|
21 |
!True class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
384
|
26 |
All Rights Reserved
|
1
|
27 |
|
88
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
!
|
1
|
36 |
|
88
|
37 |
documentation
|
|
38 |
"
|
|
39 |
True has only one instance, true, representing logical truth.
|
1238
|
40 |
|
88
|
41 |
Some methods are implemented here and in False, instead of the common
|
|
42 |
superclass Boolean. This has the advantage, that no truth-value checks
|
|
43 |
are needed, but instead the thruth check is done in the method lookup.
|
|
44 |
However, remember that some messages to booleans are inline coded in
|
|
45 |
the compilers (both interpreted and machine code). Therefore redefinition
|
|
46 |
of some methods here will not have any effect on compiled code.
|
|
47 |
(redefining ifTrue: to something else will probably crash the smalltalk
|
|
48 |
world anyway ...)
|
1294
|
49 |
|
1303
|
50 |
[see also:]
|
|
51 |
False
|
|
52 |
|
1294
|
53 |
[author:]
|
|
54 |
Claus Gittinger
|
88
|
55 |
"
|
|
56 |
! !
|
1
|
57 |
|
13598
|
58 |
!True class methodsFor:'others'!
|
|
59 |
|
|
60 |
version_CVS
|
|
61 |
^ '$Header: /cvs/stx/stx/libbasic/True.st,v 1.30 2011-08-20 14:32:02 cg Exp $'
|
|
62 |
! !
|
|
63 |
|
11758
|
64 |
|
693
|
65 |
!True methodsFor:'conditional evaluation'!
|
1
|
66 |
|
|
67 |
and:aBlock
|
|
68 |
"evaluate aBlock if the receiver is true.
|
|
69 |
since the receiver is known to be true,
|
|
70 |
return the value of evaluating the block.
|
3044
|
71 |
Notice:
|
|
72 |
This method is open coded (inlined) by the compiler(s)
|
|
73 |
- redefining it may not work as expected."
|
1
|
74 |
|
|
75 |
^ aBlock value
|
|
76 |
!
|
|
77 |
|
11817
|
78 |
and:block1 and:block2
|
11826
|
79 |
"evaluate block1 if the receiver is true,
|
|
80 |
if that is also true, return the result from block2."
|
11817
|
81 |
|
13598
|
82 |
block1 value ifFalse: [^ false].
|
|
83 |
^ block2 value
|
|
84 |
|
|
85 |
"Modified: / 20-08-2011 / 16:31:27 / cg"
|
11817
|
86 |
!
|
|
87 |
|
11826
|
88 |
and:block1 and:block2 and:block3
|
11918
|
89 |
"evaluate block1 if the receiver is true,
|
|
90 |
if that is also true, evaluate block2.
|
|
91 |
if that is also true, return the result from block3."
|
|
92 |
|
11826
|
93 |
block1 value ifFalse:[^ false].
|
|
94 |
block2 value ifFalse:[^ false].
|
|
95 |
^ block3 value
|
|
96 |
!
|
|
97 |
|
|
98 |
and:block1 and:block2 and:block3 and:block4
|
11918
|
99 |
"evaluate block1 if the receiver is true,
|
|
100 |
if that is also true, evaluate block2.
|
|
101 |
if that is also true, evaluate block3.
|
|
102 |
if that is also true, return the result from block4."
|
|
103 |
|
11826
|
104 |
block1 value ifFalse:[^ false].
|
|
105 |
block2 value ifFalse:[^ false].
|
|
106 |
block3 value ifFalse:[^ false].
|
|
107 |
^ block4 value
|
|
108 |
!
|
|
109 |
|
1
|
110 |
ifFalse:aBlock
|
9224
|
111 |
"If the receiver is false, return the value of evaluating aBlock; nil otherwise.
|
|
112 |
Since the receiver is definitely true here, unconditionally return nil value.
|
3044
|
113 |
Notice:
|
9224
|
114 |
This method is open coded (inlined) by the compiler(s)
|
|
115 |
- redefining it may not work as expected."
|
1
|
116 |
|
|
117 |
^ nil
|
|
118 |
!
|
|
119 |
|
693
|
120 |
ifFalse:falseBlock ifTrue:trueBlock
|
|
121 |
"return the value of evaluating trueBlock (since the receiver is true)
|
3044
|
122 |
Notice:
|
|
123 |
This method is open coded (inlined) by the compiler(s)
|
|
124 |
- redefining it may not work as expected."
|
693
|
125 |
|
|
126 |
^ trueBlock value
|
|
127 |
!
|
|
128 |
|
|
129 |
ifTrue:aBlock
|
9224
|
130 |
"If the receiver is true, return the value of evaluating aBlock; nil otherwise.
|
|
131 |
Since the receiver is definitely true here, unconditionally return the blocks value.
|
3044
|
132 |
Notice:
|
9224
|
133 |
This method is open coded (inlined) by the compiler(s)
|
|
134 |
- redefining it may not work as expected."
|
693
|
135 |
|
|
136 |
^ aBlock value
|
|
137 |
!
|
|
138 |
|
1
|
139 |
ifTrue:trueBlock ifFalse:falseBlock
|
|
140 |
"return the value of evaluating trueBlock (since the receiver is true)
|
3044
|
141 |
Notice:
|
|
142 |
This method is open coded (inlined) by the compiler(s)
|
|
143 |
- redefining it may not work as expected."
|
1
|
144 |
|
|
145 |
^ trueBlock value
|
|
146 |
!
|
|
147 |
|
693
|
148 |
or:aBlock
|
|
149 |
"evaluate aBlock if the receiver is false.
|
|
150 |
since the receiver is known to be true simply return true.
|
3044
|
151 |
Notice:
|
|
152 |
This method is open coded (inlined) by the compiler(s)
|
|
153 |
- redefining it may not work as expected."
|
1
|
154 |
|
693
|
155 |
^ self
|
11826
|
156 |
!
|
|
157 |
|
|
158 |
or:block1 or:block2
|
|
159 |
^ self
|
|
160 |
!
|
|
161 |
|
|
162 |
or:block1 or:block2 or:block3
|
|
163 |
^ self
|
|
164 |
!
|
|
165 |
|
|
166 |
or:block1 or:block2 or:block3 or:block4
|
|
167 |
^ self
|
1
|
168 |
! !
|
|
169 |
|
10816
|
170 |
!True methodsFor:'converting'!
|
|
171 |
|
11758
|
172 |
asInteger
|
|
173 |
"false->0; true->1"
|
|
174 |
|
|
175 |
^ 1
|
|
176 |
!
|
|
177 |
|
10816
|
178 |
asNumber
|
|
179 |
"false->0; true->1"
|
|
180 |
|
|
181 |
^ 1
|
|
182 |
! !
|
|
183 |
|
693
|
184 |
!True methodsFor:'logical operations'!
|
|
185 |
|
|
186 |
& aBoolean
|
|
187 |
"return true if both the receiver and the argument are true
|
6906
|
188 |
(since the receiver is true, return the argument, aBoolen)
|
|
189 |
Notice:
|
|
190 |
as this is a binary message, the argument is always evaluated.
|
|
191 |
It might be better to use and:[...], which does not evaluate
|
|
192 |
the argument if the receiver is already false."
|
693
|
193 |
|
|
194 |
^ aBoolean
|
|
195 |
!
|
|
196 |
|
|
197 |
eqv:aBoolean
|
|
198 |
"return true if both the receiver and the argument are the same truth value
|
|
199 |
(since the receiver is true, return true if the argument is also)"
|
|
200 |
|
|
201 |
^ aBoolean
|
|
202 |
!
|
|
203 |
|
9000
|
204 |
implies:aBoolean
|
|
205 |
"return true if receiver => argument"
|
|
206 |
|
|
207 |
^ aBoolean
|
|
208 |
!
|
|
209 |
|
693
|
210 |
not
|
|
211 |
"return true if the receiver is false, false otherwise
|
3044
|
212 |
(since the receiver is true, return false).
|
|
213 |
Notice:
|
|
214 |
This method is open coded (inlined) by the compiler(s)
|
|
215 |
- redefining it may not work as expected."
|
693
|
216 |
|
|
217 |
^ false
|
|
218 |
!
|
|
219 |
|
|
220 |
xor:aBoolean
|
|
221 |
"return true if the receiver and the argument are different truth values
|
|
222 |
(since the receiver is true, return true, if the argument is not)"
|
|
223 |
|
|
224 |
^ aBoolean not
|
|
225 |
!
|
|
226 |
|
|
227 |
| aBoolean
|
6906
|
228 |
"return true if either the receiver or the argument are true
|
|
229 |
(since the receiver is true, return true).
|
|
230 |
Notice:
|
|
231 |
as this is a binary message, the argument is always evaluated.
|
|
232 |
It might be better to use or:[...], which does not evaluate
|
|
233 |
the argument if the receiver is already true."
|
693
|
234 |
|
|
235 |
^ true
|
|
236 |
! !
|
|
237 |
|
|
238 |
!True methodsFor:'printing & storing'!
|
1
|
239 |
|
|
240 |
printString
|
65
|
241 |
"return character sequence representing the receiver"
|
1
|
242 |
|
|
243 |
^ 'true'
|
|
244 |
! !
|
2
|
245 |
|
693
|
246 |
!True class methodsFor:'documentation'!
|
2
|
247 |
|
693
|
248 |
version
|
13598
|
249 |
^ '$Header: /cvs/stx/stx/libbasic/True.st,v 1.30 2011-08-20 14:32:02 cg Exp $'
|
2
|
250 |
! !
|