author | Claus Gittinger <cg@exept.de> |
Thu, 23 Nov 1995 15:23:19 +0100 | |
changeset 624 | f09ad5cf21d4 |
parent 530 | 07d0bce293c9 |
child 693 | fb4d82421da8 |
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 |
" |
|
12 |
||
13 |
Boolean subclass:#True |
|
14 |
instanceVariableNames:'' |
|
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Kernel-Objects' |
|
18 |
! |
|
19 |
||
88 | 20 |
!True class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
384 | 25 |
All Rights Reserved |
1 | 26 |
|
88 | 27 |
This software is furnished under a license and may be used |
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
1 | 35 |
|
88 | 36 |
version |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
37 |
^ '$Header: /cvs/stx/stx/libbasic/True.st,v 1.13 1995-11-11 15:28:01 cg Exp $' |
88 | 38 |
! |
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
True has only one instance, true, representing logical truth. |
|
43 |
Some methods are implemented here and in False, instead of the common |
|
44 |
superclass Boolean. This has the advantage, that no truth-value checks |
|
45 |
are needed, but instead the thruth check is done in the method lookup. |
|
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 ...) |
|
51 |
" |
|
52 |
! ! |
|
1 | 53 |
|
54 |
!True methodsFor: 'logical operations'! |
|
55 |
||
56 |
& aBoolean |
|
57 |
"return true if both the receiver and the argument are true |
|
58 |
(since the receiver is true, return the argument, aBoolen)" |
|
59 |
||
60 |
^ aBoolean |
|
61 |
! |
|
62 |
||
63 |
| aBoolean |
|
64 |
"return true if either the receiver or the argument are true |
|
65 |
(since the receiver is true, return true)" |
|
66 |
||
67 |
^ true |
|
68 |
! |
|
69 |
||
70 |
not |
|
71 |
"return true if the receiver is false, false otherwise |
|
72 |
(since the receiver is true, return false)" |
|
73 |
||
74 |
^ false |
|
75 |
! |
|
76 |
||
77 |
eqv:aBoolean |
|
78 |
"return true if both the receiver and the argument are the same truth value |
|
79 |
(since the receiver is true, return true if the argument is also)" |
|
80 |
||
81 |
^ aBoolean |
|
82 |
! |
|
83 |
||
84 |
xor:aBoolean |
|
85 |
"return true if the receiver and the argument are different truth values |
|
86 |
(since the receiver is true, return true, if the argument is not)" |
|
87 |
||
88 |
^ aBoolean not |
|
89 |
! ! |
|
90 |
||
91 |
!True methodsFor: 'conditional evaluation'! |
|
92 |
||
93 |
and:aBlock |
|
94 |
"evaluate aBlock if the receiver is true. |
|
95 |
since the receiver is known to be true, |
|
96 |
return the value of evaluating the block. |
|
97 |
- open coded by compiler" |
|
98 |
||
99 |
^ aBlock value |
|
100 |
! |
|
101 |
||
102 |
or:aBlock |
|
103 |
"evaluate aBlock if the receiver is false. |
|
104 |
since the receiver is known to be true simply return true. |
|
105 |
- open coded by compiler" |
|
106 |
||
107 |
^ self |
|
108 |
! |
|
109 |
||
110 |
ifTrue:aBlock |
|
111 |
"return the value of evaluating aBlock (since the receiver is true) |
|
112 |
- open coded by compiler" |
|
113 |
||
114 |
^ aBlock value |
|
115 |
! |
|
116 |
||
117 |
ifFalse:aBlock |
|
118 |
"return the true alternative, nil (since the receiver is true) |
|
119 |
- open coded by compiler" |
|
120 |
||
121 |
^ nil |
|
122 |
! |
|
123 |
||
124 |
ifTrue:trueBlock ifFalse:falseBlock |
|
125 |
"return the value of evaluating trueBlock (since the receiver is true) |
|
126 |
- open coded by compiler" |
|
127 |
||
128 |
^ trueBlock value |
|
129 |
! |
|
130 |
||
131 |
ifFalse:falseBlock ifTrue:trueBlock |
|
132 |
"return the value of evaluating trueBlock (since the receiver is true) |
|
133 |
- open coded by compiler" |
|
134 |
||
135 |
^ trueBlock value |
|
136 |
! ! |
|
137 |
||
95 | 138 |
!True methodsFor: 'printing & storing'! |
1 | 139 |
|
140 |
printString |
|
65 | 141 |
"return character sequence representing the receiver" |
1 | 142 |
|
143 |
^ 'true' |
|
144 |
! ! |
|
2 | 145 |
|
146 |
!True methodsFor: 'binary storage'! |
|
147 |
||
148 |
storeBinaryOn: stream manager: manager |
|
41 | 149 |
"store a binary representation of the receiver on stream; |
150 |
redefined, since true is stored with a special type-code" |
|
151 |
||
2 | 152 |
stream nextPut: manager codeForTrue |
153 |
! ! |