22580
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
1
|
3 |
"
|
5
|
4 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
384
|
5 |
All Rights Reserved
|
1
|
6 |
|
|
7 |
This software is furnished under a license and may be used
|
|
8 |
only in accordance with the terms of that license and with the
|
|
9 |
inclusion of the above copyright notice. This software may not
|
|
10 |
be provided or otherwise made available to, or used by, any
|
|
11 |
other person. No title to or ownership of the software is
|
|
12 |
hereby transferred.
|
|
13 |
"
|
6906
|
14 |
"{ Package: 'stx:libbasic' }"
|
|
15 |
|
19705
|
16 |
"{ NameSpace: Smalltalk }"
|
|
17 |
|
1
|
18 |
Boolean subclass:#True
|
1238
|
19 |
instanceVariableNames:''
|
|
20 |
classVariableNames:''
|
|
21 |
poolDictionaries:''
|
|
22 |
category:'Kernel-Objects'
|
1
|
23 |
!
|
|
24 |
|
88
|
25 |
!True class methodsFor:'documentation'!
|
|
26 |
|
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
384
|
30 |
All Rights Reserved
|
1
|
31 |
|
88
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
|
39 |
!
|
1
|
40 |
|
88
|
41 |
documentation
|
|
42 |
"
|
|
43 |
True has only one instance, true, representing logical truth.
|
1238
|
44 |
|
88
|
45 |
Some methods are implemented here and in False, instead of the common
|
20196
|
46 |
superclass Boolean. This has the advantage that no truth-value checks
|
|
47 |
are needed, but instead the truth check is done in the method lookup.
|
88
|
48 |
However, remember that some messages to booleans are inline coded in
|
|
49 |
the compilers (both interpreted and machine code). Therefore redefinition
|
|
50 |
of some methods here will not have any effect on compiled code.
|
|
51 |
(redefining ifTrue: to something else will probably crash the smalltalk
|
|
52 |
world anyway ...)
|
1294
|
53 |
|
1303
|
54 |
[see also:]
|
|
55 |
False
|
20196
|
56 |
|
1294
|
57 |
[author:]
|
|
58 |
Claus Gittinger
|
88
|
59 |
"
|
|
60 |
! !
|
1
|
61 |
|
11758
|
62 |
|
20196
|
63 |
|
693
|
64 |
!True methodsFor:'conditional evaluation'!
|
1
|
65 |
|
|
66 |
and:aBlock
|
|
67 |
"evaluate aBlock if the receiver is true.
|
|
68 |
since the receiver is known to be true,
|
|
69 |
return the value of evaluating the block.
|
3044
|
70 |
Notice:
|
|
71 |
This method is open coded (inlined) by the compiler(s)
|
|
72 |
- redefining it may not work as expected."
|
1
|
73 |
|
|
74 |
^ aBlock value
|
|
75 |
!
|
|
76 |
|
11817
|
77 |
and:block1 and:block2
|
11826
|
78 |
"evaluate block1 if the receiver is true,
|
22673
|
79 |
if that is also true, return the result from block2.
|
|
80 |
Notice:
|
|
81 |
This method may be open coded (inlined) by the compiler(s)
|
|
82 |
- redefining it may not work as expected."
|
11817
|
83 |
|
13598
|
84 |
block1 value ifFalse: [^ false].
|
|
85 |
^ block2 value
|
|
86 |
|
|
87 |
"Modified: / 20-08-2011 / 16:31:27 / cg"
|
11817
|
88 |
!
|
|
89 |
|
11826
|
90 |
and:block1 and:block2 and:block3
|
11918
|
91 |
"evaluate block1 if the receiver is true,
|
|
92 |
if that is also true, evaluate block2.
|
22673
|
93 |
if that is also true, return the result from block3.
|
|
94 |
Notice:
|
|
95 |
This method may be open coded (inlined) by the compiler(s)
|
|
96 |
- redefining it may not work as expected."
|
11918
|
97 |
|
11826
|
98 |
block1 value ifFalse:[^ false].
|
|
99 |
block2 value ifFalse:[^ false].
|
|
100 |
^ block3 value
|
|
101 |
!
|
|
102 |
|
|
103 |
and:block1 and:block2 and:block3 and:block4
|
11918
|
104 |
"evaluate block1 if the receiver is true,
|
|
105 |
if that is also true, evaluate block2.
|
|
106 |
if that is also true, evaluate block3.
|
22673
|
107 |
if that is also true, return the result from block4.
|
|
108 |
Notice:
|
|
109 |
This method may be open coded (inlined) by the compiler(s)
|
|
110 |
- redefining it may not work as expected."
|
11918
|
111 |
|
11826
|
112 |
block1 value ifFalse:[^ false].
|
|
113 |
block2 value ifFalse:[^ false].
|
|
114 |
block3 value ifFalse:[^ false].
|
|
115 |
^ block4 value
|
|
116 |
!
|
|
117 |
|
1
|
118 |
ifFalse:aBlock
|
9224
|
119 |
"If the receiver is false, return the value of evaluating aBlock; nil otherwise.
|
|
120 |
Since the receiver is definitely true here, unconditionally return nil value.
|
3044
|
121 |
Notice:
|
9224
|
122 |
This method is open coded (inlined) by the compiler(s)
|
|
123 |
- redefining it may not work as expected."
|
1
|
124 |
|
|
125 |
^ nil
|
|
126 |
!
|
|
127 |
|
693
|
128 |
ifFalse:falseBlock ifTrue:trueBlock
|
|
129 |
"return the value of evaluating trueBlock (since the receiver is true)
|
3044
|
130 |
Notice:
|
|
131 |
This method is open coded (inlined) by the compiler(s)
|
|
132 |
- redefining it may not work as expected."
|
693
|
133 |
|
|
134 |
^ trueBlock value
|
|
135 |
!
|
|
136 |
|
|
137 |
ifTrue:aBlock
|
9224
|
138 |
"If the receiver is true, return the value of evaluating aBlock; nil otherwise.
|
23891
|
139 |
Since the receiver is definitely true here, unconditionally return the block's value.
|
3044
|
140 |
Notice:
|
9224
|
141 |
This method is open coded (inlined) by the compiler(s)
|
|
142 |
- redefining it may not work as expected."
|
693
|
143 |
|
|
144 |
^ aBlock value
|
23891
|
145 |
|
|
146 |
"Modified (comment): / 13-03-2019 / 10:22:50 / Claus Gittinger"
|
693
|
147 |
!
|
|
148 |
|
1
|
149 |
ifTrue:trueBlock ifFalse:falseBlock
|
|
150 |
"return the value of evaluating trueBlock (since the receiver is 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 |
|
|
155 |
^ trueBlock value
|
|
156 |
!
|
|
157 |
|
693
|
158 |
or:aBlock
|
|
159 |
"evaluate aBlock if the receiver is false.
|
|
160 |
since the receiver is known to be true simply return true.
|
3044
|
161 |
Notice:
|
|
162 |
This method is open coded (inlined) by the compiler(s)
|
|
163 |
- redefining it may not work as expected."
|
1
|
164 |
|
693
|
165 |
^ self
|
11826
|
166 |
!
|
|
167 |
|
|
168 |
or:block1 or:block2
|
22673
|
169 |
"evaluate block1... if the receiver is false.
|
|
170 |
since the receiver is known to be true simply return true.
|
|
171 |
Notice:
|
|
172 |
This method may be open coded (inlined) by the compiler(s)
|
|
173 |
- redefining it may not work as expected."
|
|
174 |
|
11826
|
175 |
^ self
|
|
176 |
!
|
|
177 |
|
|
178 |
or:block1 or:block2 or:block3
|
22673
|
179 |
"evaluate block1... if the receiver is false.
|
|
180 |
since the receiver is known to be true simply return true.
|
|
181 |
Notice:
|
|
182 |
This method may be open coded (inlined) by the compiler(s)
|
|
183 |
- redefining it may not work as expected."
|
|
184 |
|
11826
|
185 |
^ self
|
|
186 |
!
|
|
187 |
|
|
188 |
or:block1 or:block2 or:block3 or:block4
|
22673
|
189 |
"evaluate block1... if the receiver is false.
|
|
190 |
since the receiver is known to be true simply return true.
|
|
191 |
Notice:
|
|
192 |
This method may be open coded (inlined) by the compiler(s)
|
|
193 |
- redefining it may not work as expected."
|
|
194 |
|
11826
|
195 |
^ self
|
1
|
196 |
! !
|
|
197 |
|
10816
|
198 |
!True methodsFor:'converting'!
|
|
199 |
|
11758
|
200 |
asInteger
|
|
201 |
"false->0; true->1"
|
|
202 |
|
|
203 |
^ 1
|
|
204 |
!
|
|
205 |
|
10816
|
206 |
asNumber
|
|
207 |
"false->0; true->1"
|
|
208 |
|
|
209 |
^ 1
|
|
210 |
! !
|
|
211 |
|
22052
|
212 |
!True methodsFor:'debugging'!
|
|
213 |
|
|
214 |
haltIfFalse
|
|
215 |
"halt if the receiver is false"
|
|
216 |
|
|
217 |
<resource: #skipInDebuggersWalkBack>
|
|
218 |
|
|
219 |
^ self
|
|
220 |
|
|
221 |
"
|
|
222 |
3 haltIfNil
|
|
223 |
nil haltIfNil
|
|
224 |
"
|
|
225 |
|
|
226 |
"Created: / 17-07-2017 / 17:42:56 / cg"
|
|
227 |
!
|
|
228 |
|
|
229 |
haltIfTrue
|
|
230 |
"halt if the receiver is true"
|
|
231 |
|
|
232 |
<resource: #skipInDebuggersWalkBack>
|
|
233 |
|
|
234 |
self halt
|
|
235 |
|
|
236 |
"
|
|
237 |
3 haltIfNil
|
|
238 |
nil haltIfNil
|
|
239 |
|
|
240 |
true haltIfTrue
|
|
241 |
false haltIfFalse
|
|
242 |
"
|
|
243 |
|
|
244 |
"Created: / 17-07-2017 / 17:43:32 / cg"
|
|
245 |
! !
|
|
246 |
|
23891
|
247 |
|
693
|
248 |
!True methodsFor:'logical operations'!
|
|
249 |
|
|
250 |
& aBoolean
|
|
251 |
"return true if both the receiver and the argument are true
|
6906
|
252 |
(since the receiver is true, return the argument, aBoolen)
|
|
253 |
Notice:
|
|
254 |
as this is a binary message, the argument is always evaluated.
|
|
255 |
It might be better to use and:[...], which does not evaluate
|
|
256 |
the argument if the receiver is already false."
|
693
|
257 |
|
|
258 |
^ aBoolean
|
|
259 |
!
|
|
260 |
|
22580
|
261 |
==> aBoolean
|
23409
|
262 |
"same as implies:
|
|
263 |
return true if receiver => argument"
|
22580
|
264 |
|
|
265 |
^ aBoolean
|
23409
|
266 |
|
|
267 |
"Modified (comment): / 09-10-2018 / 09:02:40 / Claus Gittinger"
|
22580
|
268 |
!
|
|
269 |
|
693
|
270 |
eqv:aBoolean
|
|
271 |
"return true if both the receiver and the argument are the same truth value
|
|
272 |
(since the receiver is true, return true if the argument is also)"
|
|
273 |
|
|
274 |
^ aBoolean
|
|
275 |
!
|
|
276 |
|
9000
|
277 |
implies:aBoolean
|
|
278 |
"return true if receiver => argument"
|
|
279 |
|
|
280 |
^ aBoolean
|
|
281 |
!
|
|
282 |
|
693
|
283 |
not
|
|
284 |
"return true if the receiver is false, false otherwise
|
3044
|
285 |
(since the receiver is true, return false).
|
|
286 |
Notice:
|
|
287 |
This method is open coded (inlined) by the compiler(s)
|
|
288 |
- redefining it may not work as expected."
|
693
|
289 |
|
|
290 |
^ false
|
|
291 |
!
|
|
292 |
|
|
293 |
xor:aBoolean
|
|
294 |
"return true if the receiver and the argument are different truth values
|
|
295 |
(since the receiver is true, return true, if the argument is not)"
|
|
296 |
|
|
297 |
^ aBoolean not
|
|
298 |
!
|
|
299 |
|
|
300 |
| aBoolean
|
6906
|
301 |
"return true if either the receiver or the argument are true
|
|
302 |
(since the receiver is true, return true).
|
|
303 |
Notice:
|
|
304 |
as this is a binary message, the argument is always evaluated.
|
|
305 |
It might be better to use or:[...], which does not evaluate
|
|
306 |
the argument if the receiver is already true."
|
693
|
307 |
|
|
308 |
^ true
|
|
309 |
! !
|
|
310 |
|
|
311 |
!True methodsFor:'printing & storing'!
|
1
|
312 |
|
|
313 |
printString
|
65
|
314 |
"return character sequence representing the receiver"
|
1
|
315 |
|
|
316 |
^ 'true'
|
|
317 |
! !
|
2
|
318 |
|
693
|
319 |
!True class methodsFor:'documentation'!
|
2
|
320 |
|
693
|
321 |
version
|
19705
|
322 |
^ '$Header$'
|
|
323 |
!
|
|
324 |
|
|
325 |
version_CVS
|
|
326 |
^ '$Header$'
|
2
|
327 |
! !
|
19705
|
328 |
|