True.st
author Claus Gittinger <cg@exept.de>
Thu, 25 Apr 1996 19:02:53 +0200
changeset 1295 83f594f05c52
parent 1294 e26bbb61f6b2
child 1303 8fdc2c653d13
permissions -rw-r--r--
documentation
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
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
Boolean subclass:#True
1238
a1b8da9895ad commentary
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
    14
	instanceVariableNames:''
a1b8da9895ad commentary
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
    15
	classVariableNames:''
a1b8da9895ad commentary
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
    16
	poolDictionaries:''
a1b8da9895ad commentary
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
    17
	category:'Kernel-Objects'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
88
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    20
!True class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    21
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    24
 COPYRIGHT (c) 1988 by Claus Gittinger
384
claus
parents: 378
diff changeset
    25
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    26
88
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    34
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    35
88
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    36
documentation
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    37
"
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    38
    True has only one instance, true, representing logical truth.
1238
a1b8da9895ad commentary
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
    39
88
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    40
    Some methods are implemented here and in False, instead of the common
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    41
    superclass Boolean. This has the advantage, that no truth-value checks
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    42
    are needed, but instead the thruth check is done in the method lookup.
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    43
    However, remember that some messages to booleans are inline coded in
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    44
    the compilers (both interpreted and machine code). Therefore redefinition
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    45
    of some methods here will not have any effect on compiled code.
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    46
    (redefining ifTrue: to something else will probably crash the smalltalk
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    47
     world anyway ...)
1294
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1238
diff changeset
    48
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1238
diff changeset
    49
    [author:]
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1238
diff changeset
    50
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    51
"
81dacba7a63a *** empty log message ***
claus
parents: 65
diff changeset
    52
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    53
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    54
!True methodsFor:'binary storage'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    55
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    56
storeBinaryOn: stream manager: manager
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    57
    "store a binary representation of the receiver on stream;
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    58
     redefined, since true is stored with a special type-code"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    59
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    60
    stream nextPut: manager codeForTrue
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    61
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    62
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    63
!True methodsFor:'conditional evaluation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    64
a27a279701f8 Initial revision
claus
parents:
diff changeset
    65
and:aBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
    66
    "evaluate aBlock if the receiver is true.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    67
     since the receiver is known to be true,
a27a279701f8 Initial revision
claus
parents:
diff changeset
    68
     return the value of evaluating the block.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    69
     - open coded by compiler"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    70
a27a279701f8 Initial revision
claus
parents:
diff changeset
    71
    ^ aBlock value
a27a279701f8 Initial revision
claus
parents:
diff changeset
    72
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    73
a27a279701f8 Initial revision
claus
parents:
diff changeset
    74
ifFalse:aBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
    75
    "return the true alternative, nil (since the receiver is true)
a27a279701f8 Initial revision
claus
parents:
diff changeset
    76
     - open coded by compiler"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    77
a27a279701f8 Initial revision
claus
parents:
diff changeset
    78
    ^ nil
a27a279701f8 Initial revision
claus
parents:
diff changeset
    79
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    80
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    81
ifFalse:falseBlock ifTrue:trueBlock
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    82
    "return the value of evaluating trueBlock (since the receiver is true)
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    83
     - open coded by compiler"
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    84
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    85
    ^ trueBlock value
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    86
!
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    87
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    88
ifTrue:aBlock
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    89
    "return the value of evaluating aBlock (since the receiver is true)
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    90
     - open coded by compiler"
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    91
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    92
    ^ aBlock value
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    93
!
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    94
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    95
ifTrue:trueBlock ifFalse:falseBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
    96
    "return the value of evaluating trueBlock (since the receiver is true)
a27a279701f8 Initial revision
claus
parents:
diff changeset
    97
     - open coded by compiler"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    98
a27a279701f8 Initial revision
claus
parents:
diff changeset
    99
    ^ trueBlock value
a27a279701f8 Initial revision
claus
parents:
diff changeset
   100
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   101
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   102
or:aBlock
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   103
    "evaluate aBlock if the receiver is false.
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   104
     since the receiver is known to be true simply return true.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   105
     - open coded by compiler"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   106
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   107
    ^ self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   108
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   109
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   110
!True methodsFor:'logical operations'!
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   111
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   112
& aBoolean
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   113
   "return true if both the receiver and the argument are true
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   114
    (since the receiver is true, return the argument, aBoolen)"
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   115
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   116
    ^ aBoolean
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   117
!
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   118
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   119
eqv:aBoolean
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   120
   "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
   121
    (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
   122
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   123
    ^ aBoolean
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   124
!
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   125
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   126
not
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   127
   "return true if the receiver is false, false otherwise
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   128
    (since the receiver is true, return false)"
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   129
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   130
    ^ false
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   131
!
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   132
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   133
xor:aBoolean
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   134
   "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
   135
    (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
   136
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   137
    ^ aBoolean not
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
| aBoolean
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   141
   "return true if either the receiver or the argument are true
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   142
    (since the receiver is true, return true)"
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
    ^ true
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
!True methodsFor:'printing & storing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   148
a27a279701f8 Initial revision
claus
parents:
diff changeset
   149
printString
65
63f19c1157b6 *** empty log message ***
claus
parents: 41
diff changeset
   150
    "return character sequence representing the receiver"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   151
a27a279701f8 Initial revision
claus
parents:
diff changeset
   152
    ^ 'true'
a27a279701f8 Initial revision
claus
parents:
diff changeset
   153
! !
2
claus
parents: 1
diff changeset
   154
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   155
!True class methodsFor:'documentation'!
2
claus
parents: 1
diff changeset
   156
693
fb4d82421da8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   157
version
1294
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1238
diff changeset
   158
    ^ '$Header: /cvs/stx/stx/libbasic/True.st,v 1.17 1996-04-25 16:51:53 cg Exp $'
2
claus
parents: 1
diff changeset
   159
! !