True.st
author Stefan Vogel <sv@exept.de>
Wed, 01 Sep 2004 16:45:23 +0200
changeset 8508 68cd95545196
parent 6906 87afb9964006
child 9000 74a49b889c33
permissions -rw-r--r--
Allow to proceed with any stream from an #openError handler
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1988 by Claus Gittinger
384
claus
parents: 378
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
6906
87afb9964006 comments
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
    13
"{ Package: 'stx:libbasic' }"
87afb9964006 comments
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
    14
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    15
Boolean subclass:#True
1238
a1b8da9895ad commentary
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
    16
	instanceVariableNames:''
a1b8da9895ad commentary
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
    17
	classVariableNames:''
a1b8da9895ad commentary
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
    18
	poolDictionaries:''
a1b8da9895ad commentary
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
    19
	category:'Kernel-Objects'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
88
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    22
!True class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    23
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    26
 COPYRIGHT (c) 1988 by Claus Gittinger
384
claus
parents: 378
diff changeset
    27
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    28
88
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    36
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    37
88
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    38
documentation
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    39
"
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    40
    True has only one instance, true, representing logical truth.
1238
a1b8da9895ad commentary
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
    41
88
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    42
    Some methods are implemented here and in False, instead of the common
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    43
    superclass Boolean. This has the advantage, that no truth-value checks
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    44
    are needed, but instead the thruth check is done in the method lookup.
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    45
    However, remember that some messages to booleans are inline coded in
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    46
    the compilers (both interpreted and machine code). Therefore redefinition
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    47
    of some methods here will not have any effect on compiled code.
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    48
    (redefining ifTrue: to something else will probably crash the smalltalk
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    49
     world anyway ...)
1294
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1238
diff changeset
    50
1303
8fdc2c653d13 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
    51
    [see also:]
8fdc2c653d13 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
    52
        False
8fdc2c653d13 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
    53
        
1294
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1238
diff changeset
    54
    [author:]
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1238
diff changeset
    55
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    56
"
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    57
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    58
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    59
!True methodsFor:'binary storage'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    60
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    61
storeBinaryOn: stream manager: manager
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    62
    "store a binary representation of the receiver on stream;
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    63
     redefined, since true is stored with a special type-code"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    64
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    65
    stream nextPut: manager codeForTrue
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    66
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    67
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    68
!True methodsFor:'conditional evaluation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    69
a27a279701f8 Initial revision
claus
parents:
diff changeset
    70
and:aBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
    71
    "evaluate aBlock if the receiver is true.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    72
     since the receiver is known to be true,
a27a279701f8 Initial revision
claus
parents:
diff changeset
    73
     return the value of evaluating the block.
3044
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
    74
     Notice:
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
    75
	This method is open coded (inlined) by the compiler(s)
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
    76
	- redefining it may not work as expected."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    77
a27a279701f8 Initial revision
claus
parents:
diff changeset
    78
    ^ aBlock value
a27a279701f8 Initial revision
claus
parents:
diff changeset
    79
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    80
a27a279701f8 Initial revision
claus
parents:
diff changeset
    81
ifFalse:aBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
    82
    "return the true alternative, nil (since the receiver is true)
3044
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
    83
     Notice:
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
    84
	This method is open coded (inlined) by the compiler(s)
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
    85
	- redefining it may not work as expected."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    86
a27a279701f8 Initial revision
claus
parents:
diff changeset
    87
    ^ nil
a27a279701f8 Initial revision
claus
parents:
diff changeset
    88
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    89
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    90
ifFalse:falseBlock ifTrue:trueBlock
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    91
    "return the value of evaluating trueBlock (since the receiver is true)
3044
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
    92
     Notice:
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
    93
	This method is open coded (inlined) by the compiler(s)
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
    94
	- redefining it may not work as expected."
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    95
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    96
    ^ trueBlock value
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    97
!
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    98
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    99
ifTrue:aBlock
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   100
    "return the value of evaluating aBlock (since the receiver is true)
3044
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   101
     Notice:
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   102
	This method is open coded (inlined) by the compiler(s)
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   103
	- redefining it may not work as expected."
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   104
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   105
    ^ aBlock value
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   106
!
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   107
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   108
ifTrue:trueBlock ifFalse:falseBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
   109
    "return the value of evaluating trueBlock (since the receiver is true)
3044
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   110
     Notice:
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   111
	This method is open coded (inlined) by the compiler(s)
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   112
	- redefining it may not work as expected."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   113
a27a279701f8 Initial revision
claus
parents:
diff changeset
   114
    ^ trueBlock value
a27a279701f8 Initial revision
claus
parents:
diff changeset
   115
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   116
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   117
or:aBlock
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   118
    "evaluate aBlock if the receiver is false.
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   119
     since the receiver is known to be true simply return true.
3044
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   120
     Notice:
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   121
	This method is open coded (inlined) by the compiler(s)
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   122
	- redefining it may not work as expected."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   123
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   124
    ^ self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   125
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   126
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   127
!True methodsFor:'logical operations'!
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   128
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   129
& aBoolean
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   130
   "return true if both the receiver and the argument are true
6906
87afb9964006 comments
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   131
    (since the receiver is true, return the argument, aBoolen)
87afb9964006 comments
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   132
     Notice: 
87afb9964006 comments
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   133
         as this is a binary message, the argument is always evaluated. 
87afb9964006 comments
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   134
         It might be better to use and:[...], which does not evaluate
87afb9964006 comments
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   135
         the argument if the receiver is already false."
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   136
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   137
    ^ aBoolean
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   138
!
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   139
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   140
eqv:aBoolean
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   141
   "return true if both the receiver and the argument are the same truth value
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   142
    (since the receiver is true, return true if the argument is also)"
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   143
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   144
    ^ aBoolean
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   145
!
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   146
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   147
not
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   148
   "return true if the receiver is false, false otherwise
3044
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   149
    (since the receiver is true, return false).
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   150
    Notice:
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   151
	This method is open coded (inlined) by the compiler(s)
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   152
	- redefining it may not work as expected."
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   153
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   154
    ^ false
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   155
!
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   156
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   157
xor:aBoolean
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   158
   "return true if the receiver and the argument are different truth values
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   159
    (since the receiver is true, return true, if the argument is not)"
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   160
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   161
    ^ aBoolean not
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   162
!
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   163
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   164
| aBoolean
6906
87afb9964006 comments
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   165
    "return true if either the receiver or the argument are true
87afb9964006 comments
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   166
     (since the receiver is true, return true).
87afb9964006 comments
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   167
     Notice: 
87afb9964006 comments
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   168
         as this is a binary message, the argument is always evaluated. 
87afb9964006 comments
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   169
         It might be better to use or:[...], which does not evaluate
87afb9964006 comments
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   170
         the argument if the receiver is already true."
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   171
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   172
    ^ true
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   173
! !
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   174
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   175
!True methodsFor:'printing & storing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   176
a27a279701f8 Initial revision
claus
parents:
diff changeset
   177
printString
65
63f19c1157b6 *** empty log message ***
claus
parents: 41
diff changeset
   178
    "return character sequence representing the receiver"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   179
a27a279701f8 Initial revision
claus
parents:
diff changeset
   180
    ^ 'true'
a27a279701f8 Initial revision
claus
parents:
diff changeset
   181
! !
2
claus
parents: 1
diff changeset
   182
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   183
!True class methodsFor:'documentation'!
2
claus
parents: 1
diff changeset
   184
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   185
version
6906
87afb9964006 comments
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   186
    ^ '$Header: /cvs/stx/stx/libbasic/True.st,v 1.20 2002-11-26 15:48:37 cg Exp $'
2
claus
parents: 1
diff changeset
   187
! !