author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 31 Oct 2011 22:19:21 +0000 | |
branch | jv |
changeset 17892 | d86c8bd5ece3 |
parent 17869 | 9610c6c94e71 |
child 17910 | 8d796ca8bd1d |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
379 | 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:#False |
1238 | 15 |
instanceVariableNames:'' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Kernel-Objects' |
|
1 | 19 |
! |
20 |
||
88 | 21 |
!False class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
379 | 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 |
False has only one instance, false, representing logical falsehood. |
|
1238 | 40 |
|
88 | 41 |
Some methods are implemented here and in True, 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 |
True |
|
52 |
||
1294 | 53 |
[author:] |
54 |
Claus Gittinger |
|
574 | 55 |
" |
692 | 56 |
! ! |
1 | 57 |
|
11759 | 58 |
|
1 | 59 |
!False methodsFor:'conditional evaluation'! |
60 |
||
61 |
and:aBlock |
|
62 |
"evaluate aBlock if the receiver is true. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
63 |
(since the receiver is known to be false here, always return false here). |
3044 | 64 |
Notice: |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
65 |
This method is open coded (inlined) by the compiler(s) |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
66 |
- redefining it may not work as expected." |
1 | 67 |
|
68 |
^ self |
|
69 |
! |
|
70 |
||
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
71 |
and:block1 and:block2 |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
72 |
"evaluate block1 if the receiver is true; if that also returns true, evaluate block2. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
73 |
(since the receiver is known to be false here, always return false here). |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
74 |
Notice: |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
75 |
This method is open coded (inlined) by the compiler(s) |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
76 |
- redefining it may not work as expected." |
17728
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 |
^ self |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
79 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
80 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
81 |
and:block1 and:block2 and:block3 |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
82 |
"return false" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
83 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
84 |
^ self |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
85 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
86 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
87 |
and:block1 and:block2 and:block3 and:block4 |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
88 |
"return false" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
89 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
90 |
^ self |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
91 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
92 |
|
1 | 93 |
ifFalse:aBlock |
9225 | 94 |
"If the receiver is false, return the value of evaluating aBlock; nil otherwise. |
95 |
Since the receiver is definitely false here, unconditionally return the blocks value. |
|
3044 | 96 |
Notice: |
9225 | 97 |
This method is open coded (inlined) by the compiler(s) |
98 |
- redefining it may not work as expected." |
|
1 | 99 |
|
100 |
^ aBlock value |
|
101 |
! |
|
102 |
||
574 | 103 |
ifFalse:falseBlock ifTrue:trueBlock |
104 |
"return the value of evaluating falseBlock (since the receiver is false) |
|
3044 | 105 |
Notice: |
106 |
This method is open coded (inlined) by the compiler(s) |
|
107 |
- redefining it may not work as expected." |
|
574 | 108 |
|
109 |
^ falseBlock value |
|
110 |
! |
|
111 |
||
1 | 112 |
ifTrue:aBlock |
9225 | 113 |
"If the receiver is true, return the value of evaluating aBlock; nil otherwise. |
114 |
Since the receiver is definitely false here, unconditionally return nil value. |
|
3044 | 115 |
Notice: |
9225 | 116 |
This method is open coded (inlined) by the compiler(s) |
117 |
- redefining it may not work as expected." |
|
1 | 118 |
|
119 |
^ nil |
|
120 |
! |
|
121 |
||
122 |
ifTrue:trueBlock ifFalse:falseBlock |
|
123 |
"return the value of evaluating falseBlock (since the receiver is false) |
|
3044 | 124 |
Notice: |
125 |
This method is open coded (inlined) by the compiler(s) |
|
126 |
- redefining it may not work as expected." |
|
1 | 127 |
|
128 |
^ falseBlock value |
|
129 |
! |
|
130 |
||
574 | 131 |
or:aBlock |
132 |
"evaluate aBlock if the receiver is false. |
|
133 |
(since the receiver is false return the value of evaluating aBlock). |
|
3044 | 134 |
Notice: |
135 |
This method is open coded (inlined) by the compiler(s) |
|
136 |
- redefining it may not work as expected." |
|
1 | 137 |
|
574 | 138 |
^ aBlock value |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
139 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
140 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
141 |
or:block1 or:block2 |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
142 |
block1 value ifTrue:[^ true]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
143 |
^ block2 value |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
144 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
145 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
146 |
or:block1 or:block2 or:block3 |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
147 |
block1 value ifTrue:[^ true]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
148 |
block2 value ifTrue:[^ true]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
149 |
^ block3 value |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
150 |
! |
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 |
or:block1 or:block2 or:block3 or:block4 |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
153 |
block1 value ifTrue:[^ true]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
154 |
block2 value ifTrue:[^ true]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
155 |
block3 value ifTrue:[^ true]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
156 |
^ block4 value |
1 | 157 |
! ! |
158 |
||
10817 | 159 |
!False methodsFor:'converting'! |
160 |
||
11759 | 161 |
asInteger |
162 |
"false->0; true->1" |
|
163 |
||
164 |
^ 0 |
|
165 |
! |
|
166 |
||
10817 | 167 |
asNumber |
168 |
"false->0; true->1" |
|
169 |
||
170 |
^ 0 |
|
171 |
! ! |
|
172 |
||
574 | 173 |
!False methodsFor:'logical operations'! |
174 |
||
175 |
& aBoolean |
|
176 |
"return true, if both the receiver and the argument are true |
|
6906 | 177 |
(since the receiver is false, return false) |
178 |
Notice: |
|
179 |
as this is a binary message, the argument is always evaluated. |
|
180 |
It might be better to use and:[...], which does not evaluate |
|
181 |
the argument if the receiver is already false." |
|
574 | 182 |
|
183 |
^ false |
|
184 |
! |
|
185 |
||
186 |
eqv:aBoolean |
|
187 |
"return true, if the receiver and the argument are the same truth value |
|
188 |
(since the receiver is false, return true if the argument is also false)" |
|
189 |
||
190 |
^ aBoolean not |
|
191 |
! |
|
192 |
||
9000 | 193 |
implies:aBoolean |
194 |
"return true if receiver => argument" |
|
195 |
||
196 |
^ true |
|
197 |
! |
|
198 |
||
574 | 199 |
not |
200 |
"return true, if the receiver is false, false otherwise |
|
3044 | 201 |
(since the receiver is false, return true). |
202 |
Notice: |
|
203 |
This method is open coded (inlined) by the compiler(s) |
|
204 |
- redefining it may not work as expected." |
|
574 | 205 |
|
206 |
^ true |
|
207 |
! |
|
208 |
||
209 |
xor:aBoolean |
|
210 |
"return true, if the receiver and the argument are different truth values |
|
211 |
(since the receiver is false, return true, if the armument is not false)" |
|
212 |
||
213 |
^ aBoolean |
|
214 |
! |
|
215 |
||
216 |
| aBoolean |
|
217 |
"return true, if either the receiver or the argument is true |
|
6906 | 218 |
(since the receiver is false, return the argument). |
219 |
Notice: |
|
220 |
as this is a binary message, the argument is always evaluated. |
|
221 |
It might be better to use or:[...], which does not evaluate |
|
222 |
the argument if the receiver is already true." |
|
574 | 223 |
|
224 |
^ aBoolean |
|
225 |
! ! |
|
226 |
||
227 |
!False methodsFor:'printing & storing'! |
|
1 | 228 |
|
229 |
printString |
|
54 | 230 |
"return character sequence representing the receiver" |
1 | 231 |
|
232 |
^ 'false' |
|
233 |
! ! |
|
2 | 234 |
|
692 | 235 |
!False class methodsFor:'documentation'! |
236 |
||
237 |
version |
|
17892 | 238 |
^ '$Header: /cvs/stx/stx/libbasic/False.st,v 1.28 2009/09/14 12:49:49 cg Exp $' |
17865 | 239 |
! |
240 |
||
241 |
version_SVN |
|
17892 | 242 |
^ '$Id: False.st 10729 2011-10-31 22:19:21Z vranyj1 $' |
17846 | 243 |
! ! |
17892 | 244 |