Symbol.st
author Claus Gittinger <cg@exept.de>
Fri, 18 Apr 1997 18:24:01 +0200
changeset 2565 90973ec63991
parent 2416 588d5d510c10
child 2570 26616a00d5aa
permissions -rw-r--r--
*** empty log message ***
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
159
514c749165c3 *** empty log message ***
claus
parents: 95
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
String subclass:#Symbol
1020
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    14
	instanceVariableNames:''
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    15
	classVariableNames:''
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    16
	poolDictionaries:''
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    17
	category:'Collections-Text'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    20
!Symbol class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
 COPYRIGHT (c) 1988 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
    25
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    36
documentation
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    37
"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    38
    Symbols represent unique strings - every symbol with same printString
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    39
    exists exactly once in the system; Symbols are used for selectors, global
345
claus
parents: 329
diff changeset
    40
    variable-keys etc. Symbols can also be used to represent things which are
claus
parents: 329
diff changeset
    41
    enumeration type values in other programming languages (since symbols are
370
claus
parents: 356
diff changeset
    42
    created at compile time, comparing them using == is a fast pointer compare).
345
claus
parents: 329
diff changeset
    43
claus
parents: 329
diff changeset
    44
    A symbol may not change its characters - i.e. it is constant over its lifetime.
claus
parents: 329
diff changeset
    45
    Other than that, symbols behave much like strings.
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1253
diff changeset
    46
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1253
diff changeset
    47
    [author:]
2200
a2b25d9e5cac MKSYMBOL has only 2 args
Claus Gittinger <cg@exept.de>
parents: 1864
diff changeset
    48
	Claus Gittinger
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    49
"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    50
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    51
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    52
!Symbol class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    53
62
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    54
basicNew:size
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    55
    "redefined to return a string instead of a symbol -
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    56
     this allows all copy methods inherited from String to
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    57
     return strings containing the symbols characters.
1020
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    58
     Real symbols are only created with #intern: or #asSymbol."
62
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    59
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    60
    ^ String new:size
1020
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    61
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    62
    "Modified: 26.2.1996 / 12:51:38 / cg"
62
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    63
!
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    64
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    65
fromString:aString
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    66
    "same as intern: for Symbol, but may be used to create interned instances
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    67
     of subclasses.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    68
     Notice: this fails, if you try to intern an instance of a subclass, AND
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    69
     a symbol with the same name already exists. In this case, the original
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    70
     symbol is returned. To use it for enum-type symbols, make certain, that the
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    71
     names are unique (for example by including the classes name as a prefix-string)."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    72
267
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    73
    |sym len|
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    74
267
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    75
    sym := aString asSymbolIfInterned.
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    76
    sym notNil ifTrue:[
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    77
	^ sym
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    78
    ].
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    79
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    80
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    81
     create a new uninterned instance first
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    82
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    83
    len := aString size.
267
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    84
    sym := super basicNew:len.
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    85
    sym replaceFrom:1 to:len with:aString.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    86
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    87
    "now, intern it"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    88
%{
329
claus
parents: 314
diff changeset
    89
    sym = __INTERNSYMBOL(sym, (OBJ *)0, __context);
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    90
%}.
267
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    91
    ^ sym
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    92
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    93
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
    94
intern:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
    95
    "return a unique symbol with printname taken from the String-argument"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
    96
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
    97
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
    98
    OBJ newSymbol;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
    99
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   100
    if (__isSymbol(aString)) {
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   101
	RETURN (aString);
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   102
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   103
    if (__isString(aString)) {
2200
a2b25d9e5cac MKSYMBOL has only 2 args
Claus Gittinger <cg@exept.de>
parents: 1864
diff changeset
   104
	newSymbol = __MKSYMBOL(__stringVal(aString), (OBJ *)0);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   105
	if (newSymbol != nil) {
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   106
	    RETURN (newSymbol);
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   107
	}
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   108
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   109
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   110
    aString class ~~ String ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   111
	"/
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   112
	"/ only allowed to intern strings
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   113
	"/
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   114
	^ self mustBeString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   115
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   116
    ^ ObjectMemory allocationFailureSignal raise.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   117
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   118
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   119
internCharacter:aCharacter
a27a279701f8 Initial revision
claus
parents:
diff changeset
   120
    "return a unique symbol with printname taken from the Character-argument"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   121
a27a279701f8 Initial revision
claus
parents:
diff changeset
   122
    ^ self intern:(aCharacter asString)
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   123
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   124
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   125
new:size
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   126
    "redefined to return a string instead of a symbol -
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   127
     this allows all copy methods inherited from String to
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   128
     return strings containing the symbols characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   129
     Real symbols are only created with intern: or asSymbol."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   130
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   131
    ^ String new:size
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   132
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   133
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   134
!Symbol class methodsFor:'binary storage'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   135
1253
7265cbaa8ec9 commentary
Claus Gittinger <cg@exept.de>
parents: 1219
diff changeset
   136
binaryDefinitionFrom:stream manager:manager
7265cbaa8ec9 commentary
Claus Gittinger <cg@exept.de>
parents: 1219
diff changeset
   137
    "retrieve a symbol from a binary input stream (nonpublic interface)"
7265cbaa8ec9 commentary
Claus Gittinger <cg@exept.de>
parents: 1219
diff changeset
   138
7265cbaa8ec9 commentary
Claus Gittinger <cg@exept.de>
parents: 1219
diff changeset
   139
    ^ self intern:(super binaryDefinitionFrom:stream manager:manager)
7265cbaa8ec9 commentary
Claus Gittinger <cg@exept.de>
parents: 1219
diff changeset
   140
7265cbaa8ec9 commentary
Claus Gittinger <cg@exept.de>
parents: 1219
diff changeset
   141
    "Modified: 22.4.1996 / 16:15:56 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   142
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   143
a27a279701f8 Initial revision
claus
parents:
diff changeset
   144
!Symbol class methodsFor:'queries'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   145
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   146
findInterned:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   147
    "for ST-80 compatibility - if the argument, aString is known
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   148
     as Symbol, return this symbol. Otherwise return nil."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   149
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   150
    ^ aString asSymbolIfInterned
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   151
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   152
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   153
hasInterned:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   154
    "return true, if the argument, aString is known as Symbol;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   155
     false otherwise"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   156
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   157
    ^ aString knownAsSymbol
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   158
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   159
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   160
hasInterned:aString ifTrue:trueBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
   161
    "for ST-80 compatibility - if the argument, aString is known
a27a279701f8 Initial revision
claus
parents:
diff changeset
   162
     as Symbol, evaluate the block with the corresponding symbol
a27a279701f8 Initial revision
claus
parents:
diff changeset
   163
     as argument and return true; otherwise return false"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   164
275
a76029ddaa98 *** empty log message ***
claus
parents: 268
diff changeset
   165
    |sym|
a76029ddaa98 *** empty log message ***
claus
parents: 268
diff changeset
   166
a76029ddaa98 *** empty log message ***
claus
parents: 268
diff changeset
   167
    (sym := aString asSymbolIfInterned) notNil ifTrue:[
a76029ddaa98 *** empty log message ***
claus
parents: 268
diff changeset
   168
	trueBlock value:sym.
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   169
	^ true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   170
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   171
    ^ false
a27a279701f8 Initial revision
claus
parents:
diff changeset
   172
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   173
a27a279701f8 Initial revision
claus
parents:
diff changeset
   174
!Symbol methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   175
a27a279701f8 Initial revision
claus
parents:
diff changeset
   176
basicAt:index put:something
345
claus
parents: 329
diff changeset
   177
    "report an error if an interned symbol is about to be changed
1219
054f7eff0c30 commentary
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   178
     - interned symbols may NOT be changed.
054f7eff0c30 commentary
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   179
     For uninterned symbols, this is allowed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   180
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   181
    self knownAsSymbol ifTrue:[
2200
a2b25d9e5cac MKSYMBOL has only 2 args
Claus Gittinger <cg@exept.de>
parents: 1864
diff changeset
   182
	self error:'interned symbols may not be changed'.
a2b25d9e5cac MKSYMBOL has only 2 args
Claus Gittinger <cg@exept.de>
parents: 1864
diff changeset
   183
	^ something
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   184
    ].
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   185
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   186
     uninterned - allow change
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   187
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   188
    ^ super basicAt:index put:something
1219
054f7eff0c30 commentary
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   189
054f7eff0c30 commentary
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   190
    "Modified: 19.4.1996 / 11:16:10 / cg"
252
   191
!
   192
   193
byteAt:index put:value
   194
    "report an error if interned - interned symbols may not be changed."
   195
   196
    ^ self basicAt:index put:(value asCharacter)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   197
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   198
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   199
!Symbol methodsFor:'comparing'!
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   200
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   201
= something
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   202
    "return true, if the receiver and argument consist of the same characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   203
     Redefined here, for more efficient #= comparison of symbols 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   204
     (which ought to be compared using #==).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   205
     If the argument is a symbol, we use a quick pointer compare, instead of
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   206
     the inherited value compare."
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   207
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   208
%{   /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   209
    OBJ cls;
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   210
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   211
    if (! __isNonNilObject(something)) RETURN(false);
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   212
    if ((cls = __qClass(something)) == Symbol) {
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   213
	RETURN (self == something ? true : false);
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   214
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   215
    if (cls == String) {
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   216
	RETURN (strcmp(__stringVal(self), __stringVal(something)) == 0 ? true : false); 
345
claus
parents: 329
diff changeset
   217
    }
claus
parents: 329
diff changeset
   218
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   219
    "fall back; could be a TwoByteString, or a collection of Characters"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   220
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   221
    ^ super = something
427
claus
parents: 384
diff changeset
   222
!
claus
parents: 384
diff changeset
   223
356
claus
parents: 345
diff changeset
   224
identityHash
claus
parents: 345
diff changeset
   225
    "interned symbols can return a better hash key"
claus
parents: 345
diff changeset
   226
claus
parents: 345
diff changeset
   227
%{  /* NOCONTEXT */
claus
parents: 345
diff changeset
   228
claus
parents: 345
diff changeset
   229
    REGISTER int g, val;
claus
parents: 345
diff changeset
   230
    REGISTER unsigned char *cp, *cp0;
claus
parents: 345
diff changeset
   231
    int l;
claus
parents: 345
diff changeset
   232
claus
parents: 345
diff changeset
   233
    if (__Class(self) == Symbol) {
375
claus
parents: 370
diff changeset
   234
	val = __GET_HASH(self);
356
claus
parents: 345
diff changeset
   235
	/*
claus
parents: 345
diff changeset
   236
	 * only do it, if I have no standard hash key
375
claus
parents: 370
diff changeset
   237
	 * assigned (which can only happen due to a #become:,
claus
parents: 370
diff changeset
   238
	 * or by creating a symbol uninterned, and interning it
claus
parents: 370
diff changeset
   239
	 * after it got a hashKey assigned.
356
claus
parents: 345
diff changeset
   240
	 */
claus
parents: 345
diff changeset
   241
	if (val == 0) {
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1125
diff changeset
   242
	    cp = __stringVal(self);
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1125
diff changeset
   243
	    l = __stringSize(self);
356
claus
parents: 345
diff changeset
   244
        
claus
parents: 345
diff changeset
   245
	    /*
claus
parents: 345
diff changeset
   246
	     * this is the dragon-book algorithm
claus
parents: 345
diff changeset
   247
	     *
claus
parents: 345
diff changeset
   248
	     * the algorithm hashes pretty good:
claus
parents: 345
diff changeset
   249
	     *   with (currently) 9963 symbols in the system,
claus
parents: 345
diff changeset
   250
	     *   there are only about 200 hash key collisions.
claus
parents: 345
diff changeset
   251
	     *   where the maximum collision count in these 200
claus
parents: 345
diff changeset
   252
	     *   is 3. This means, that in most situations,
claus
parents: 345
diff changeset
   253
	     *   a single probe will find the right element in
claus
parents: 345
diff changeset
   254
	     *   a symbol-hashed collection.
claus
parents: 345
diff changeset
   255
	     */
claus
parents: 345
diff changeset
   256
	    val = 0;
claus
parents: 345
diff changeset
   257
	    for (cp0 = cp, cp += l - 1; cp >= cp0; cp--) {
claus
parents: 345
diff changeset
   258
		val = (val << 5) + (*cp & 0x1F);
claus
parents: 345
diff changeset
   259
		if (g = (val & 0x3E000000))
claus
parents: 345
diff changeset
   260
		    val ^= g >> 25 /* 23 */ /* 25 */;
claus
parents: 345
diff changeset
   261
		val &= 0x3FFFFFFF;
claus
parents: 345
diff changeset
   262
	    }
claus
parents: 345
diff changeset
   263
claus
parents: 345
diff changeset
   264
	    if (l) {
claus
parents: 345
diff changeset
   265
		l |= 1; 
claus
parents: 345
diff changeset
   266
		val = (val * l) & 0x3FFFFFFF;
claus
parents: 345
diff changeset
   267
	    }
375
claus
parents: 370
diff changeset
   268
	} else {
claus
parents: 370
diff changeset
   269
	    val <<= __HASH_SHIFT__;
356
claus
parents: 345
diff changeset
   270
	}
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1125
diff changeset
   271
	RETURN ( __MKSMALLINT(val) );
356
claus
parents: 345
diff changeset
   272
     }
claus
parents: 345
diff changeset
   273
%}.
claus
parents: 345
diff changeset
   274
     ^ super identityHash
370
claus
parents: 356
diff changeset
   275
!
claus
parents: 356
diff changeset
   276
claus
parents: 356
diff changeset
   277
~= something
claus
parents: 356
diff changeset
   278
    "return true, if the receiver and argument do not consist of the same characters.
claus
parents: 356
diff changeset
   279
     Redefined here, for more efficient #~= comparison of symbols 
claus
parents: 356
diff changeset
   280
     (which ought to be compared using #~~).
claus
parents: 356
diff changeset
   281
     If the argument is a symbol, we use a quick pointer compare, instead of
claus
parents: 356
diff changeset
   282
     the inherited value compare."
claus
parents: 356
diff changeset
   283
claus
parents: 356
diff changeset
   284
%{   /* NOCONTEXT */
claus
parents: 356
diff changeset
   285
    OBJ cls;
claus
parents: 356
diff changeset
   286
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   287
    if (! __isNonNilObject(something)) RETURN(true);    /* cannot be equal */
370
claus
parents: 356
diff changeset
   288
    if ((cls = __qClass(something)) == Symbol) {
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   289
	RETURN (self == something ? false : true);
370
claus
parents: 356
diff changeset
   290
    }
claus
parents: 356
diff changeset
   291
    if (cls == String) {
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   292
	RETURN (strcmp(__stringVal(self), __stringVal(something)) == 0 ? false : true);
370
claus
parents: 356
diff changeset
   293
    }
claus
parents: 356
diff changeset
   294
%}.
claus
parents: 356
diff changeset
   295
    "fall back; could be a TwoByteString, or a collection of Characters"
claus
parents: 356
diff changeset
   296
claus
parents: 356
diff changeset
   297
    ^ super ~= something
356
claus
parents: 345
diff changeset
   298
! !
claus
parents: 345
diff changeset
   299
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   300
!Symbol methodsFor:'converting'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   301
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   302
asString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   303
    "return a string with printname taken from mine"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   304
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   305
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   306
    OBJ s;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   307
2565
90973ec63991 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2416
diff changeset
   308
    s = __MKSTRING_ST(self);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   309
    if (s != nil) {
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   310
	RETURN (s);
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   311
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   312
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   313
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   314
     memory allocation (for the new string) failed.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   315
     When we arrive here, there was no memory, even after a garbage collect.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   316
     This means, that the VM wanted to get some more memory from the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   317
     OS, which was not kind enough to give it.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   318
     Bad luck - you should increase the swap space on your machine,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   319
     or if you have set a soft memoryLimit, increase it.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   320
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   321
    ^ ObjectMemory allocationFailureSignal raise.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   322
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   323
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   324
asSymbol
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   325
    "return the receiver as a symbol.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   326
     Since I am a symbol - just return myself"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   327
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   328
    ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   329
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   330
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   331
asSymbolIfInterned
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   332
    "return the receiver as a symbol if there is one.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   333
     Since I am a symbol - just return myself"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   334
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   335
    ^ self
2416
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2200
diff changeset
   336
!
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2200
diff changeset
   337
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2200
diff changeset
   338
decodeAsLiteralArray
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2200
diff changeset
   339
    "given a literalEncoding in the receiver,
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2200
diff changeset
   340
     create & return the corresponding object.
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2200
diff changeset
   341
     The inverse operation to #literalArrayEncoding."
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2200
diff changeset
   342
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2200
diff changeset
   343
    ^ self
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2200
diff changeset
   344
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2200
diff changeset
   345
    "Created: 25.2.1997 / 19:15:26 / cg"
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 2200
diff changeset
   346
    "Modified: 25.2.1997 / 19:17:40 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   347
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   348
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   349
!Symbol methodsFor:'copying'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   350
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   351
copy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   352
    "return a copy of myself
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   353
     - reimplemented here since symbols are unique and copy should
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   354
     return a new string with my characters."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   355
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   356
     ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   357
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   358
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   359
deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   360
    "return a copy of myself
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   361
     - reimplemented here since symbols are unique and copy should
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   362
     return a new string with my characters."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   363
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   364
     ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   365
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   366
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   367
deepCopyUsing:aDictionary
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   368
    "return a copy of myself
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   369
     - reimplemented here since symbols are unique and copy should
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   370
     return a new string with my characters."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   371
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   372
     ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   373
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   374
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   375
shallowCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   376
    "return a copy of myself
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   377
     - reimplemented here since symbols are unique"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   378
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   379
     ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   380
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   381
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   382
simpleDeepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   383
    "return a copy of myself
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   384
     - reimplemented here since symbols are unique and copy should
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   385
     return a new string with my characters."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   386
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   387
     ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   388
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   389
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   390
!Symbol methodsFor:'printing & storing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   391
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   392
displayString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   393
    "return a string for displaying the receiver"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   394
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   395
    ^ self storeString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   396
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   397
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   398
printOn:aStream
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   399
    "append a printed representation of the receiver on aStream.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   400
     In contrast to ST-80, this does return the symbols characters
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   401
     without any leading #. Therefore, you can directly send symbols'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   402
     printStrings to some output device. This is incompatible, but easier
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   403
     to use."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   404
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   405
"/ ST-80 behavior:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   406
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   407
"/  self storeOn:aStream
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   408
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   409
    aStream nextPutAll:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   410
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   411
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   412
printString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   413
    "return a printed representation of the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   414
     In contrast to ST-80, this does return the symbols characters
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   415
     without any leading #. Therefore, you can directly send symbols'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   416
     printStrings to some output device. This is incompatible, but easier
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   417
     to use."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   418
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   419
"/ ST-80 behavior:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   420
"/  ^ self storeString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   421
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   422
    ^ self asString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   423
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   424
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   425
storeOn:aStream
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   426
    "store myself on a stream"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   427
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   428
    aStream nextPutAll:(self storeString)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   429
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   430
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   431
storeString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   432
    "return a String for storing the receiver"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   433
1125
2bfcfb490837 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1020
diff changeset
   434
    |sz|
2bfcfb490837 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1020
diff changeset
   435
2bfcfb490837 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1020
diff changeset
   436
    (sz := self size) > 0 ifTrue:[  "/ sigh
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   437
	(self at:1) isLetter ifTrue:[
1125
2bfcfb490837 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1020
diff changeset
   438
	    2 to:sz do:[:index |
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   439
		(self at:index) isLetterOrDigit ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   440
		    ^ '#''' , self , ''''
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   441
		].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   442
	    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   443
	    ^ '#' , self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   444
	]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   445
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   446
    ^ '#''' , self , ''''
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   447
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   448
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   449
!Symbol methodsFor:'queries'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   450
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   451
isSymbol 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   452
    "return true, if the receiver is some kind of symbol.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   453
     Since I am a symbol, return always true"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   454
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   455
    ^ true
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   456
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   457
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   458
keywords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   459
    "assuming the receiver is a keyword message selector,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   460
     return the individual keywords (i.e. break it up at colons)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   461
     and return these as a collection.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   462
     For binary and unary selectors, the result may be nonsense."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   463
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   464
    |coll s part|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   465
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   466
    coll := OrderedCollection new.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   467
    s := ReadStream on:self.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   468
    [s atEnd] whileFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   469
	part := s through:$:.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   470
	coll add:part
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   471
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   472
    ^ coll asArray
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   473
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   474
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   475
     #at:put: keywords  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   476
     #at: keywords      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   477
     #+ keywords        
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   478
     #size keywords     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   479
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   480
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   481
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   482
species
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   483
    "when copying, or concatenating, return instances of this class"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   484
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   485
    ^ String
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   486
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   487
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   488
!Symbol methodsFor:'system primitives'!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   489
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   490
become:anotherObject
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   491
    "make all references to the receiver become references to anotherObject
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   492
     and vice-versa. For symbols, some special action is required, to
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   493
     correctly handle a become of the global dictionaries.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   494
     Anyway: this is very dangerous - mysterous side-effects are to be
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   495
     expected.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   496
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   497
     Notice: because of the danger here, this method may report an error
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   498
	     in future versions"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   499
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   500
    (Smalltalk includesKey:self) ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   501
	super become:anotherObject.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   502
%{
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   503
	__rehashSystemDictionaries();
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   504
%}.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   505
    ] ifFalse:[
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   506
	super become:anotherObject
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   507
    ]
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   508
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   509
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   510
becomeNil
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   511
    "make all references to the receiver become nil - effectively getting
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   512
     rid of the receiver. For symbols, this is not allowed, if the receiver
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   513
     is used as a key in some SytemDictionary.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   514
     This can be a very dangerous operation - be warned.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   515
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   516
     Notice: because of the danger here, this method may report an error
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   517
	     in future versions"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   518
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   519
    (Smalltalk includesKey:self) ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   520
	self primitiveFailed
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   521
    ] ifFalse:[
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   522
	super becomeNil
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   523
    ]
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   524
! !
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   525
632
31498e8b424c version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   526
!Symbol class methodsFor:'documentation'!
31498e8b424c version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   527
31498e8b424c version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   528
version
2565
90973ec63991 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2416
diff changeset
   529
    ^ '$Header: /cvs/stx/stx/libbasic/Symbol.st,v 1.46 1997-04-18 16:24:01 cg Exp $'
632
31498e8b424c version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   530
! !