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