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 |
"
|
|
12 |
|
6906
|
13 |
"{ Package: 'stx:libbasic' }"
|
|
14 |
|
1
|
15 |
Boolean subclass:#True
|
1238
|
16 |
instanceVariableNames:''
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Kernel-Objects'
|
1
|
20 |
!
|
|
21 |
|
88
|
22 |
!True class methodsFor:'documentation'!
|
|
23 |
|
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
384
|
27 |
All Rights Reserved
|
1
|
28 |
|
88
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
!
|
1
|
37 |
|
88
|
38 |
documentation
|
|
39 |
"
|
|
40 |
True has only one instance, true, representing logical truth.
|
1238
|
41 |
|
88
|
42 |
Some methods are implemented here and in False, instead of the common
|
|
43 |
superclass Boolean. This has the advantage, that no truth-value checks
|
|
44 |
are needed, but instead the thruth check is done in the method lookup.
|
|
45 |
However, remember that some messages to booleans are inline coded in
|
|
46 |
the compilers (both interpreted and machine code). Therefore redefinition
|
|
47 |
of some methods here will not have any effect on compiled code.
|
|
48 |
(redefining ifTrue: to something else will probably crash the smalltalk
|
|
49 |
world anyway ...)
|
1294
|
50 |
|
1303
|
51 |
[see also:]
|
|
52 |
False
|
|
53 |
|
1294
|
54 |
[author:]
|
|
55 |
Claus Gittinger
|
88
|
56 |
"
|
|
57 |
! !
|
1
|
58 |
|
|
59 |
|
693
|
60 |
!True methodsFor:'conditional evaluation'!
|
1
|
61 |
|
|
62 |
and:aBlock
|
|
63 |
"evaluate aBlock if the receiver is true.
|
|
64 |
since the receiver is known to be true,
|
|
65 |
return the value of evaluating the block.
|
3044
|
66 |
Notice:
|
|
67 |
This method is open coded (inlined) by the compiler(s)
|
|
68 |
- redefining it may not work as expected."
|
1
|
69 |
|
|
70 |
^ aBlock value
|
|
71 |
!
|
|
72 |
|
|
73 |
ifFalse:aBlock
|
9224
|
74 |
"If the receiver is false, return the value of evaluating aBlock; nil otherwise.
|
|
75 |
Since the receiver is definitely true here, unconditionally return nil value.
|
3044
|
76 |
Notice:
|
9224
|
77 |
This method is open coded (inlined) by the compiler(s)
|
|
78 |
- redefining it may not work as expected."
|
1
|
79 |
|
|
80 |
^ nil
|
|
81 |
!
|
|
82 |
|
693
|
83 |
ifFalse:falseBlock ifTrue:trueBlock
|
|
84 |
"return the value of evaluating trueBlock (since the receiver is true)
|
3044
|
85 |
Notice:
|
|
86 |
This method is open coded (inlined) by the compiler(s)
|
|
87 |
- redefining it may not work as expected."
|
693
|
88 |
|
|
89 |
^ trueBlock value
|
|
90 |
!
|
|
91 |
|
|
92 |
ifTrue:aBlock
|
9224
|
93 |
"If the receiver is true, return the value of evaluating aBlock; nil otherwise.
|
|
94 |
Since the receiver is definitely true here, unconditionally return the blocks value.
|
3044
|
95 |
Notice:
|
9224
|
96 |
This method is open coded (inlined) by the compiler(s)
|
|
97 |
- redefining it may not work as expected."
|
693
|
98 |
|
|
99 |
^ aBlock value
|
|
100 |
!
|
|
101 |
|
1
|
102 |
ifTrue:trueBlock ifFalse:falseBlock
|
|
103 |
"return the value of evaluating trueBlock (since the receiver is true)
|
3044
|
104 |
Notice:
|
|
105 |
This method is open coded (inlined) by the compiler(s)
|
|
106 |
- redefining it may not work as expected."
|
1
|
107 |
|
|
108 |
^ trueBlock value
|
|
109 |
!
|
|
110 |
|
693
|
111 |
or:aBlock
|
|
112 |
"evaluate aBlock if the receiver is false.
|
|
113 |
since the receiver is known to be true simply return true.
|
3044
|
114 |
Notice:
|
|
115 |
This method is open coded (inlined) by the compiler(s)
|
|
116 |
- redefining it may not work as expected."
|
1
|
117 |
|
693
|
118 |
^ self
|
1
|
119 |
! !
|
|
120 |
|
693
|
121 |
!True methodsFor:'logical operations'!
|
|
122 |
|
|
123 |
& aBoolean
|
|
124 |
"return true if both the receiver and the argument are true
|
6906
|
125 |
(since the receiver is true, return the argument, aBoolen)
|
|
126 |
Notice:
|
|
127 |
as this is a binary message, the argument is always evaluated.
|
|
128 |
It might be better to use and:[...], which does not evaluate
|
|
129 |
the argument if the receiver is already false."
|
693
|
130 |
|
|
131 |
^ aBoolean
|
|
132 |
!
|
|
133 |
|
|
134 |
eqv:aBoolean
|
|
135 |
"return true if both the receiver and the argument are the same truth value
|
|
136 |
(since the receiver is true, return true if the argument is also)"
|
|
137 |
|
|
138 |
^ aBoolean
|
|
139 |
!
|
|
140 |
|
9000
|
141 |
implies:aBoolean
|
|
142 |
"return true if receiver => argument"
|
|
143 |
|
|
144 |
^ aBoolean
|
|
145 |
!
|
|
146 |
|
693
|
147 |
not
|
|
148 |
"return true if the receiver is false, false otherwise
|
3044
|
149 |
(since the receiver is true, return false).
|
|
150 |
Notice:
|
|
151 |
This method is open coded (inlined) by the compiler(s)
|
|
152 |
- redefining it may not work as expected."
|
693
|
153 |
|
|
154 |
^ false
|
|
155 |
!
|
|
156 |
|
|
157 |
xor:aBoolean
|
|
158 |
"return true if the receiver and the argument are different truth values
|
|
159 |
(since the receiver is true, return true, if the argument is not)"
|
|
160 |
|
|
161 |
^ aBoolean not
|
|
162 |
!
|
|
163 |
|
|
164 |
| aBoolean
|
6906
|
165 |
"return true if either the receiver or the argument are true
|
|
166 |
(since the receiver is true, return true).
|
|
167 |
Notice:
|
|
168 |
as this is a binary message, the argument is always evaluated.
|
|
169 |
It might be better to use or:[...], which does not evaluate
|
|
170 |
the argument if the receiver is already true."
|
693
|
171 |
|
|
172 |
^ true
|
|
173 |
! !
|
|
174 |
|
|
175 |
!True methodsFor:'printing & storing'!
|
1
|
176 |
|
|
177 |
printString
|
65
|
178 |
"return character sequence representing the receiver"
|
1
|
179 |
|
|
180 |
^ 'true'
|
|
181 |
! !
|
2
|
182 |
|
693
|
183 |
!True class methodsFor:'documentation'!
|
2
|
184 |
|
693
|
185 |
version
|
9652
|
186 |
^ '$Header: /cvs/stx/stx/libbasic/True.st,v 1.24 2006-08-23 14:06:14 cg Exp $'
|
2
|
187 |
! !
|