author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sat, 24 Oct 2009 16:48:19 +0100 | |
branch | jv |
changeset 17732 | a1892eeca6c0 |
parent 17728 | bbc5fa73dfab |
child 17761 | b0e5971141bc |
permissions | -rw-r--r-- |
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 |
|
11758 | 58 |
|
693 | 59 |
!True methodsFor:'conditional evaluation'! |
1 | 60 |
|
61 |
and:aBlock |
|
62 |
"evaluate aBlock if the receiver is true. |
|
63 |
since the receiver is known to be true, |
|
64 |
return the value of evaluating the block. |
|
3044 | 65 |
Notice: |
66 |
This method is open coded (inlined) by the compiler(s) |
|
67 |
- redefining it may not work as expected." |
|
1 | 68 |
|
69 |
^ aBlock value |
|
70 |
! |
|
71 |
||
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
72 |
and:block1 and:block2 |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
73 |
"evaluate block1 if the receiver is true, |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
74 |
if that is also true, return the result from block2." |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
75 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
76 |
^ block1 value and:block2 |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
77 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
78 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
79 |
and:block1 and:block2 and:block3 |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
80 |
"evaluate block1 if the receiver is true, |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
81 |
if that is also true, evaluate block2. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
82 |
if that is also true, return the result from block3." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
83 |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
84 |
block1 value ifFalse:[^ false]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
85 |
block2 value ifFalse:[^ false]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
86 |
^ block3 value |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
87 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
88 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
89 |
and:block1 and:block2 and:block3 and:block4 |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
90 |
"evaluate block1 if the receiver is true, |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
91 |
if that is also true, evaluate block2. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
92 |
if that is also true, evaluate block3. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
93 |
if that is also true, return the result from block4." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
94 |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
95 |
block1 value ifFalse:[^ false]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
96 |
block2 value ifFalse:[^ false]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
97 |
block3 value ifFalse:[^ false]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
98 |
^ block4 value |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
99 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
100 |
|
1 | 101 |
ifFalse:aBlock |
9224 | 102 |
"If the receiver is false, return the value of evaluating aBlock; nil otherwise. |
103 |
Since the receiver is definitely true here, unconditionally return nil value. |
|
3044 | 104 |
Notice: |
9224 | 105 |
This method is open coded (inlined) by the compiler(s) |
106 |
- redefining it may not work as expected." |
|
1 | 107 |
|
108 |
^ nil |
|
109 |
! |
|
110 |
||
693 | 111 |
ifFalse:falseBlock ifTrue:trueBlock |
112 |
"return the value of evaluating trueBlock (since the receiver is true) |
|
3044 | 113 |
Notice: |
114 |
This method is open coded (inlined) by the compiler(s) |
|
115 |
- redefining it may not work as expected." |
|
693 | 116 |
|
117 |
^ trueBlock value |
|
118 |
! |
|
119 |
||
120 |
ifTrue:aBlock |
|
9224 | 121 |
"If the receiver is true, return the value of evaluating aBlock; nil otherwise. |
122 |
Since the receiver is definitely true here, unconditionally return the blocks value. |
|
3044 | 123 |
Notice: |
9224 | 124 |
This method is open coded (inlined) by the compiler(s) |
125 |
- redefining it may not work as expected." |
|
693 | 126 |
|
127 |
^ aBlock value |
|
128 |
! |
|
129 |
||
1 | 130 |
ifTrue:trueBlock ifFalse:falseBlock |
131 |
"return the value of evaluating trueBlock (since the receiver is true) |
|
3044 | 132 |
Notice: |
133 |
This method is open coded (inlined) by the compiler(s) |
|
134 |
- redefining it may not work as expected." |
|
1 | 135 |
|
136 |
^ trueBlock value |
|
137 |
! |
|
138 |
||
693 | 139 |
or:aBlock |
140 |
"evaluate aBlock if the receiver is false. |
|
141 |
since the receiver is known to be true simply return true. |
|
3044 | 142 |
Notice: |
143 |
This method is open coded (inlined) by the compiler(s) |
|
144 |
- redefining it may not work as expected." |
|
1 | 145 |
|
693 | 146 |
^ self |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
147 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
148 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
149 |
or:block1 or:block2 |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
150 |
^ self |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
151 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
152 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
153 |
or:block1 or:block2 or:block3 |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
154 |
^ self |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
155 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
156 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
157 |
or:block1 or:block2 or:block3 or:block4 |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
158 |
^ self |
1 | 159 |
! ! |
160 |
||
10816 | 161 |
!True methodsFor:'converting'! |
162 |
||
11758 | 163 |
asInteger |
164 |
"false->0; true->1" |
|
165 |
||
166 |
^ 1 |
|
167 |
! |
|
168 |
||
10816 | 169 |
asNumber |
170 |
"false->0; true->1" |
|
171 |
||
172 |
^ 1 |
|
173 |
! ! |
|
174 |
||
693 | 175 |
!True methodsFor:'logical operations'! |
176 |
||
177 |
& aBoolean |
|
178 |
"return true if both the receiver and the argument are true |
|
6906 | 179 |
(since the receiver is true, return the argument, aBoolen) |
180 |
Notice: |
|
181 |
as this is a binary message, the argument is always evaluated. |
|
182 |
It might be better to use and:[...], which does not evaluate |
|
183 |
the argument if the receiver is already false." |
|
693 | 184 |
|
185 |
^ aBoolean |
|
186 |
! |
|
187 |
||
188 |
eqv:aBoolean |
|
189 |
"return true if both the receiver and the argument are the same truth value |
|
190 |
(since the receiver is true, return true if the argument is also)" |
|
191 |
||
192 |
^ aBoolean |
|
193 |
! |
|
194 |
||
9000 | 195 |
implies:aBoolean |
196 |
"return true if receiver => argument" |
|
197 |
||
198 |
^ aBoolean |
|
199 |
! |
|
200 |
||
693 | 201 |
not |
202 |
"return true if the receiver is false, false otherwise |
|
3044 | 203 |
(since the receiver is true, return false). |
204 |
Notice: |
|
205 |
This method is open coded (inlined) by the compiler(s) |
|
206 |
- redefining it may not work as expected." |
|
693 | 207 |
|
208 |
^ false |
|
209 |
! |
|
210 |
||
211 |
xor:aBoolean |
|
212 |
"return true if the receiver and the argument are different truth values |
|
213 |
(since the receiver is true, return true, if the argument is not)" |
|
214 |
||
215 |
^ aBoolean not |
|
216 |
! |
|
217 |
||
218 |
| aBoolean |
|
6906 | 219 |
"return true if either the receiver or the argument are true |
220 |
(since the receiver is true, return true). |
|
221 |
Notice: |
|
222 |
as this is a binary message, the argument is always evaluated. |
|
223 |
It might be better to use or:[...], which does not evaluate |
|
224 |
the argument if the receiver is already true." |
|
693 | 225 |
|
226 |
^ true |
|
227 |
! ! |
|
228 |
||
229 |
!True methodsFor:'printing & storing'! |
|
1 | 230 |
|
231 |
printString |
|
65 | 232 |
"return character sequence representing the receiver" |
1 | 233 |
|
234 |
^ 'true' |
|
235 |
! ! |
|
2 | 236 |
|
693 | 237 |
!True class methodsFor:'documentation'! |
2 | 238 |
|
693 | 239 |
version |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
240 |
^ '$Id: True.st 10473 2009-10-24 15:48:19Z vranyj1 $' |
2 | 241 |
! ! |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
242 |