Symbol.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 24241 7fcbc1f15829
child 25030 a74b4e68af6d
permissions -rw-r--r--
#REFACTORING by exept class: Smalltalk class changed: #recursiveInstallAutoloadedClassesFrom:rememberIn:maxLevels:noAutoload:packageTop:showSplashInLevels: Transcript showCR:(... bindWith:...) -> Transcript showCR:... with:...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23849
931471bc4a08 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23838
diff changeset
     1
"{ Encoding: utf8 }"
931471bc4a08 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23838
diff changeset
     2
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     3
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     4
 COPYRIGHT (c) 1988 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
     5
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
"
5434
c496158fea85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5185
diff changeset
    14
"{ Package: 'stx:libbasic' }"
c496158fea85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5185
diff changeset
    15
17512
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
    16
"{ NameSpace: Smalltalk }"
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
    17
3985
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3659
diff changeset
    18
String variableByteSubclass:#Symbol
1020
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    19
	instanceVariableNames:''
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    20
	classVariableNames:''
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    21
	poolDictionaries:''
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    22
	category:'Collections-Text'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    25
!Symbol class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    26
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    27
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 COPYRIGHT (c) 1988 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
    30
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    41
documentation
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    42
"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    43
    Symbols represent unique strings - every symbol with same printString
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    44
    exists exactly once in the system; Symbols are used for selectors, global
345
claus
parents: 329
diff changeset
    45
    variable-keys etc. Symbols can also be used to represent things which are
claus
parents: 329
diff changeset
    46
    enumeration type values in other programming languages (since symbols are
370
claus
parents: 356
diff changeset
    47
    created at compile time, comparing them using == is a fast pointer compare).
345
claus
parents: 329
diff changeset
    48
claus
parents: 329
diff changeset
    49
    A symbol may not change its characters - i.e. it is constant over its lifetime.
claus
parents: 329
diff changeset
    50
    Other than that, symbols behave much like strings.
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1253
diff changeset
    51
17512
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
    52
    The most prominent use of symbols is as key for message sending: methods are stored
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
    53
    in a classes method dictionary, where symbols are used as key to map names to methods.
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
    54
    Also, symbols are used as key to map class names (global names) to actual class objects.
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
    55
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
    56
    Special ST/X feature:
18360
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
    57
	The ST/X VM method lookup supports selector namespaces for method extensions.
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
    58
	This means, that a class may contain method extensions in another namespace,
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
    59
	which are only seen and invoked if called from a class within that namespace.
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
    60
	Technically, this is done by storing the method under a special namespace-selector,
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
    61
	which is a symbol consisting of the user visible name, prefixed by ':<ns>::'.
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
    62
	The VM's method lookup algorithm contains special handling code for such constructs.
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
    63
	Thus, if two methods are stored as 'foo' and ':NS::foo' are present in a class,
23849
931471bc4a08 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23838
diff changeset
    64
	any send of 'foo' from wíthin the NS-namespace will invoke the second method.
18360
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
    65
	Any other send will invoke the first one.
17512
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
    66
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
    67
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1253
diff changeset
    68
    [author:]
18360
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
    69
	Claus Gittinger
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    70
"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    71
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    72
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    73
!Symbol class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    74
62
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    75
basicNew:size
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    76
    "redefined to return a string instead of a symbol -
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    77
     this allows all copy methods inherited from String to
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    78
     return strings containing the symbols characters.
1020
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    79
     Real symbols are only created with #intern: or #asSymbol."
62
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    80
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    81
    ^ String new:size
1020
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    82
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    83
    "Modified: 26.2.1996 / 12:51:38 / cg"
62
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    84
!
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    85
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    86
fromString:aString
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    87
    "same as intern: for Symbol, but may be used to create interned instances
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    88
     of subclasses.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    89
     Notice: this fails, if you try to intern an instance of a subclass, AND
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    90
     a symbol with the same name already exists. In this case, the original
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    91
     symbol is returned. To use it for enum-type symbols, make certain, that the
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    92
     names are unique (for example by including the classes name as a prefix-string)."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    93
267
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    94
    |sym len|
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    95
267
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    96
    sym := aString asSymbolIfInterned.
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    97
    sym notNil ifTrue:[
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    98
	^ sym
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    99
    ].
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   100
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   101
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   102
     create a new uninterned instance first
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   103
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   104
    len := aString size.
267
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
   105
    sym := super basicNew:len.
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
   106
    sym replaceFrom:1 to:len with:aString.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   107
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   108
    "now, intern it"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   109
%{
329
claus
parents: 314
diff changeset
   110
    sym = __INTERNSYMBOL(sym, (OBJ *)0, __context);
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   111
%}.
267
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
   112
    ^ sym
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   113
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   114
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   115
intern:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   116
    "return a unique symbol with printname taken from the String-argument"
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
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   119
    OBJ newSymbol;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   120
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   121
    if (__isSymbol(aString)) {
13882
187a02bd5c99 OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents: 13881
diff changeset
   122
	RETURN (aString);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   123
    }
12473
828e275ddf8b change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11859
diff changeset
   124
    if (__isStringLike(aString)) {
13882
187a02bd5c99 OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents: 13881
diff changeset
   125
	newSymbol = __MKSYMBOL(__stringVal(aString), (OBJ *)0);
187a02bd5c99 OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents: 13881
diff changeset
   126
	if (newSymbol != nil) {
187a02bd5c99 OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents: 13881
diff changeset
   127
	    RETURN (newSymbol);
187a02bd5c99 OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents: 13881
diff changeset
   128
	}
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   129
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   130
%}.
12473
828e275ddf8b change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11859
diff changeset
   131
    (aString class ~~ String and:[aString class ~~ ImmutableString]) ifTrue:[
13882
187a02bd5c99 OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents: 13881
diff changeset
   132
	"only allowed to intern strings"
187a02bd5c99 OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents: 13881
diff changeset
   133
	^ self mustBeString
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   134
    ].
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   135
    ^ AllocationFailure raise.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   136
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   137
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   138
internCharacter:aCharacter
a27a279701f8 Initial revision
claus
parents:
diff changeset
   139
    "return a unique symbol with printname taken from the Character-argument"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   140
a27a279701f8 Initial revision
claus
parents:
diff changeset
   141
    ^ self intern:(aCharacter asString)
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   142
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   143
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   144
new:size
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   145
    "redefined to return a string instead of a symbol -
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   146
     this allows all copy methods inherited from String to
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   147
     return strings containing the symbols characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   148
     Real symbols are only created with intern: or asSymbol."
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
    ^ String new:size
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
2570
26616a00d5aa added #tableSize for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 2565
diff changeset
   153
23838
598b8a8934d0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23413
diff changeset
   154
598b8a8934d0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23413
diff changeset
   155
!Symbol class methodsFor:'Javascript support'!
598b8a8934d0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23413
diff changeset
   156
598b8a8934d0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23413
diff changeset
   157
for:argument
598b8a8934d0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23413
diff changeset
   158
    "Symbol.for(string) is the same as ST's string asSymbol"
598b8a8934d0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23413
diff changeset
   159
598b8a8934d0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23413
diff changeset
   160
    ^ argument asSymbol
598b8a8934d0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23413
diff changeset
   161
598b8a8934d0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23413
diff changeset
   162
    "Created: / 05-03-2019 / 09:55:55 / Claus Gittinger"
598b8a8934d0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23413
diff changeset
   163
! !
598b8a8934d0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23413
diff changeset
   164
598b8a8934d0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23413
diff changeset
   165
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   166
!Symbol class methodsFor:'queries'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   167
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   168
findInterned:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   169
    "for ST-80 compatibility - if the argument, aString is known
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   170
     as Symbol, return this symbol. Otherwise return nil."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   171
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   172
    ^ aString asSymbolIfInterned
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   173
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   174
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   175
hasInterned:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   176
    "return true, if the argument, aString is known as Symbol;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   177
     false otherwise"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   178
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   179
    ^ aString knownAsSymbol
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   180
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   181
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   182
hasInterned:aString ifTrue:trueBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
   183
    "for ST-80 compatibility - if the argument, aString is known
a27a279701f8 Initial revision
claus
parents:
diff changeset
   184
     as Symbol, evaluate the block with the corresponding symbol
a27a279701f8 Initial revision
claus
parents:
diff changeset
   185
     as argument and return true; otherwise return false"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   186
275
a76029ddaa98 *** empty log message ***
claus
parents: 268
diff changeset
   187
    |sym|
a76029ddaa98 *** empty log message ***
claus
parents: 268
diff changeset
   188
a76029ddaa98 *** empty log message ***
claus
parents: 268
diff changeset
   189
    (sym := aString asSymbolIfInterned) notNil ifTrue:[
a76029ddaa98 *** empty log message ***
claus
parents: 268
diff changeset
   190
	trueBlock value:sym.
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   191
	^ true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   192
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   193
    ^ false
4651
18a6ac30b36f added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4530
diff changeset
   194
!
18a6ac30b36f added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4530
diff changeset
   195
18a6ac30b36f added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4530
diff changeset
   196
hasSharedInstances
18a6ac30b36f added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4530
diff changeset
   197
    "return true if this class has shared instances, that is, instances
18a6ac30b36f added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4530
diff changeset
   198
     with the same value are identical.
4654
3b3f88c73a86 comment
Claus Gittinger <cg@exept.de>
parents: 4651
diff changeset
   199
     True returned here - there is only one of each symbol (per contents)."
4651
18a6ac30b36f added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4530
diff changeset
   200
18a6ac30b36f added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4530
diff changeset
   201
    ^ true
18a6ac30b36f added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4530
diff changeset
   202
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   203
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   204
13423
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   205
23838
598b8a8934d0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23413
diff changeset
   206
11819
ad671b753451 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11773
diff changeset
   207
!Symbol methodsFor:'Compatibility-Squeak'!
ad671b753451 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11773
diff changeset
   208
13690
cb522bd8a636 added: #precedence
Claus Gittinger <cg@exept.de>
parents: 13471
diff changeset
   209
precedence
cb522bd8a636 added: #precedence
Claus Gittinger <cg@exept.de>
parents: 13471
diff changeset
   210
    "the precedence in an expression; 0 is highest;
23918
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   211
        unary < binary < keyword"
13690
cb522bd8a636 added: #precedence
Claus Gittinger <cg@exept.de>
parents: 13471
diff changeset
   212
23918
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   213
    self size == 0
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   214
        ifTrue: [^ 0].
13690
cb522bd8a636 added: #precedence
Claus Gittinger <cg@exept.de>
parents: 13471
diff changeset
   215
    self first isLetter
23918
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   216
        ifFalse: [^ 2].
13690
cb522bd8a636 added: #precedence
Claus Gittinger <cg@exept.de>
parents: 13471
diff changeset
   217
    self last = $:
23918
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   218
        ifTrue: [^ 3].
13690
cb522bd8a636 added: #precedence
Claus Gittinger <cg@exept.de>
parents: 13471
diff changeset
   219
    ^ 1
cb522bd8a636 added: #precedence
Claus Gittinger <cg@exept.de>
parents: 13471
diff changeset
   220
cb522bd8a636 added: #precedence
Claus Gittinger <cg@exept.de>
parents: 13471
diff changeset
   221
    "
13882
187a02bd5c99 OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents: 13881
diff changeset
   222
     self assert:(#foo precedence < #+ precedence).
13690
cb522bd8a636 added: #precedence
Claus Gittinger <cg@exept.de>
parents: 13471
diff changeset
   223
     self assert:(#+ precedence < #key: precedence).
cb522bd8a636 added: #precedence
Claus Gittinger <cg@exept.de>
parents: 13471
diff changeset
   224
     self assert:(#foo precedence < #key: precedence).
cb522bd8a636 added: #precedence
Claus Gittinger <cg@exept.de>
parents: 13471
diff changeset
   225
    "
cb522bd8a636 added: #precedence
Claus Gittinger <cg@exept.de>
parents: 13471
diff changeset
   226
cb522bd8a636 added: #precedence
Claus Gittinger <cg@exept.de>
parents: 13471
diff changeset
   227
    "Created: / 12-09-2011 / 14:53:54 / cg"
23918
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   228
    "Modified: / 15-03-2019 / 13:35:53 / Stefan Vogel"
11819
ad671b753451 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11773
diff changeset
   229
! !
ad671b753451 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11773
diff changeset
   230
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7153
diff changeset
   231
!Symbol methodsFor:'Compatibility-VW'!
7153
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   232
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   233
<< catalogID
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   234
    "create and return a new UserMessage, with the receiver as key,
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   235
     and the argument as cataglogID.
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   236
     VW compatibility."
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   237
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   238
    ^ UserMessage key:self catalogID:catalogID
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   239
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   240
    "
11859
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   241
     (#theFooMessage << #myMessages)
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   242
     (#theFooMessage << #myMessages >> 'cannot read subclass of metaclass')
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   243
     (#theFooMessage >> 'cannot read subclass of metaclass')
7153
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   244
    "
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   245
!
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   246
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   247
>> aString
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   248
    "create and return a new UserMessage, with the receiver as key,
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   249
     and the argument as defaultString.
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   250
     VW compatibility."
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   251
11859
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   252
    ^ UserMessage key:self defaultString:aString
7153
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   253
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   254
    "
11859
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   255
     (#theFooMessage << #myMessages)
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   256
     (#theFooMessage << #myMessages >> 'cannot read subclass of metaclass')
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   257
     (#theFooMessage >> 'cannot read subclass of metaclass')
7153
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   258
    "
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   259
! !
87edd141467e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6054
diff changeset
   260
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   261
!Symbol methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   262
a27a279701f8 Initial revision
claus
parents:
diff changeset
   263
basicAt:index put:something
345
claus
parents: 329
diff changeset
   264
    "report an error if an interned symbol is about to be changed
1219
054f7eff0c30 commentary
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   265
     - interned symbols may NOT be changed.
054f7eff0c30 commentary
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   266
     For uninterned symbols, this is allowed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   267
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   268
    self knownAsSymbol ifTrue:[
16890
8fa6938075c2 refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents: 16774
diff changeset
   269
	self noModificationError.
8fa6938075c2 refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents: 16774
diff changeset
   270
	"Even if you hit continue - you cannot change symbols.
8fa6938075c2 refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents: 16774
diff changeset
   271
	 Raise again non-resumable"
8fa6938075c2 refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents: 16774
diff changeset
   272
	NoModificationError raiseWith:self errorString:' - interned symbols cannot be changed'.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   273
    ].
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   274
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   275
     uninterned - allow change
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   276
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   277
    ^ super basicAt:index put:something
1219
054f7eff0c30 commentary
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   278
054f7eff0c30 commentary
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
   279
    "Modified: 19.4.1996 / 11:16:10 / cg"
13423
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   280
!
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   281
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   282
nameSpace
16735
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   283
    "if I have the format of a namespace-selector,
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   284
     retrieve the namespace. Otherwise, return nil.
18619
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   285
     Also return nil, if that namespace does not exist (in contrast to nameSpacePart).
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   286
     Namespace selectors have a special, fix defined format, which is also known in the VM.
16735
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   287
     They must be of the form :<ns>::<sel>,
17512
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   288
     where <ns> is the namespace and <sel> is the raw selector.
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   289
     This special format (a symbol starting with a colon) was chosen, because almost every other selector
18360
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
   290
     is legal, and this can be checked quickly by just looking at the first character."
16735
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   291
17516
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   292
     |nsPart|
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   293
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   294
     nsPart := self nameSpaceAndSelectorParts first.
18619
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   295
     nsPart isNil ifTrue:[^ nil].
17516
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   296
     ^ Smalltalk at:nsPart asSymbol
16735
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   297
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   298
    "
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   299
     #':foo:' nameSpace       -> nil (bad format)
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   300
     #':foo::bar' nameSpace   -> nil (non existing)
17516
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   301
     #':Tools::bar' nameSpace -> Tools
18619
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   302
     #'bar' nameSpace -> nil
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   303
     #'bar:' nameSpace -> nil
16735
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   304
    "
13423
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   305
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   306
    "Created: / 20-07-2010 / 10:41:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   307
!
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   308
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   309
nameSpaceAndSelector
16735
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   310
    "return a two element tuple consisting of the namespace and the raw selector.
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   311
     If I do not have the format of a namespace-selector, or the namespace is non-existing,
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   312
     the first element of the returned tuple will be nil.
18619
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   313
     Namespace selectors have a special, fix defined format, which is also known in the VM.
16735
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   314
     They must be of the form :<ns>::<sel>,
17512
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   315
     where <ns> is the namespace and <sel> is the raw selector.
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   316
     This special format (a symbol starting with a colon) was chosen, because almost every other selector
18360
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
   317
     is legal, and this can be checked quickly by just looking at the first character."
16735
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   318
17516
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   319
    |parts ns|
13423
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   320
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   321
    self isNameSpaceSelector ifFalse:[
18701
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   322
	^ Array with:nil with:self
13423
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   323
    ].
17516
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   324
    parts := self nameSpaceAndSelectorParts.
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   325
    ns := Smalltalk at:parts first asSymbol.
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   326
    ^ Array with:ns with:parts second
13423
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   327
16735
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   328
    "
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   329
     #':foo:bar' nameSpaceAndSelector     -> #(nil #':foo:bar')
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   330
     #':foo::bar' nameSpaceAndSelector    -> #(nil #bar)
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   331
     #':Tools::foo' nameSpaceAndSelector  -> #(Tools (* NameSpace *) #foo)
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   332
    "
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   333
13423
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   334
    "Created: / 20-07-2010 / 10:23:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   335
!
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   336
17516
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   337
nameSpaceAndSelectorParts
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   338
    "return a two element tuple consisting of the namespace name and the raw selector.
18701
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   339
     If I do not have the format of a namespace-selector,
17516
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   340
     the first element of the returned tuple will be nil.
18619
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   341
     Namespace selectors have a special, fix defined format, which is also known in the VM.
17516
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   342
     They must be of the form :<ns>::<sel>,
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   343
     where <ns> is the namespace and <sel> is the raw selector.
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   344
     This special format (a symbol starting with a colon) was chosen, because almost every other selector
18360
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
   345
     is legal, and this can be checked quickly by just looking at the first character."
17516
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   346
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   347
     |nsPart selPart idx|
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   348
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   349
    self isNameSpaceSelector ifFalse:[
18701
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   350
	^ Array with:nil with:self
17516
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   351
    ].
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   352
    idx := self indexOf:$: startingAt:3.
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   353
    nsPart := self copyFrom:2 to:idx - 1.
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   354
    selPart := self copyFrom:idx + 2.
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   355
    ^ Array with:nsPart with:selPart asSymbol
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   356
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   357
    "
18619
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   358
     #':foo:bar' nameSpaceAndSelectorParts     -> #(nil #':foo:bar')
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   359
     #':foo:bar' nameSpaceAndSelector          -> #(nil #':foo:bar')
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   360
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   361
     #':foo::bar' nameSpaceAndSelectorParts    -> #('foo' #bar)
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   362
     #':foo::bar' nameSpaceAndSelector         -> #(nil #bar)
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   363
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   364
     #'bar' nameSpaceAndSelectorParts          -> #(nil #bar)
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   365
     #'bar' nameSpaceAndSelector               -> #(nil #bar)
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   366
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   367
     #':Tools::foo' nameSpaceAndSelectorParts  -> #('Tools' #foo)
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   368
     #':Tools::foo' nameSpaceAndSelector       -> #(Tools (* NameSpace *) #foo)
17516
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   369
    "
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   370
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   371
    "Created: / 20-07-2010 / 10:23:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   372
!
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   373
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   374
nameSpacePart
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   375
    "if I have the format of a namespace-selector,
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   376
     retrieve the namespace name. Otherwise, return nil.
18619
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   377
     Namespace selectors have a special, fix defined format, which is also known in the VM.
17516
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   378
     They must be of the form :<ns>::<sel>,
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   379
     where <ns> is the namespace and <sel> is the raw selector.
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   380
     This special format (a symbol starting with a colon) was chosen, because almost every other selector
18360
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
   381
     is legal, and this can be checked quickly by just looking at the first character."
17516
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   382
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   383
     ^ self nameSpaceAndSelectorParts first.
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   384
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   385
    "
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   386
     #':foo:' nameSpacePart       -> nil (bad format)
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   387
     #':foo::bar' nameSpacePart   -> 'foo'
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   388
     #':Tools::bar' nameSpacePart -> 'Tools'
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   389
    "
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   390
!
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   391
13423
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   392
selector
17512
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   393
    <resource: #obsolete>
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   394
18360
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
   395
    "if I have the format of a namespace-selector, retrieve the raw selector.
17512
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   396
     Otherwise, return myself.
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   397
     Namespace selectors have a special, fix defined format, which is also known in the VM.
16735
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   398
     They must be of the form :<ns>::<sel>,
17512
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   399
     where <ns> is the namespace and <sel> is the raw selector.
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   400
     This special format (a symbol starting with a colon) was chosen,
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   401
     because almost every other selector is legal,
19714
b50fc65252e4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19685
diff changeset
   402
     and this can be checked quickly in the VM, by just looking at the first character."
17512
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   403
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   404
     self obsoleteMethodWarning:'use selectorWithoutNameSpace'.
18360
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
   405
    ^ self selectorWithoutNameSpace
17512
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   406
!
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   407
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   408
selectorWithoutNameSpace
18360
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
   409
    "if I have the format of a namespace-selector, retrieve the raw selector.
17512
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   410
     Otherwise, return myself.
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   411
     Namespace selectors have a special, fix defined format, which is also known in the VM.
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   412
     They must be of the form :<ns>::<sel>,
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   413
     where <ns> is the namespace and <sel> is the raw selector.
886e6b3b419b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17185
diff changeset
   414
     This special format (a symbol starting with a colon) was chosen, because almost every other selector
18360
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
   415
     is legal, and this can be checked quickly by just looking at the first character."
16735
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   416
24121
d0148c842873 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24026
diff changeset
   417
    |idx|
d0148c842873 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24026
diff changeset
   418
d0148c842873 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24026
diff changeset
   419
    self isNameSpaceSelector ifFalse:[
d0148c842873 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24026
diff changeset
   420
        "avoid copy"    
d0148c842873 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24026
diff changeset
   421
        ^ self
d0148c842873 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24026
diff changeset
   422
    ].
d0148c842873 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24026
diff changeset
   423
    idx := self indexOf:$: startingAt:3.
d0148c842873 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24026
diff changeset
   424
    ^ self copyFrom:idx + 2.
16735
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   425
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   426
    "
17516
eda594985ae9 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 17512
diff changeset
   427
     #':foo:' selectorWithoutNameSpace       -> #':foo:' (bad format)
24121
d0148c842873 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24026
diff changeset
   428
     #':foo::bar' selectorWithoutNameSpace   -> #bar
d0148c842873 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24026
diff changeset
   429
     #':Tools::bar' selectorWithoutNameSpace -> #bar
16735
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   430
    "
13423
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   431
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   432
    "Created: / 20-07-2010 / 10:41:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
24121
d0148c842873 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24026
diff changeset
   433
    "Modified (format): / 08-05-2019 / 14:47:24 / Stefan Vogel"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   434
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   435
13423
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   436
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   437
!Symbol methodsFor:'comparing'!
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   438
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   439
= something
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   440
    "return true, if the receiver and argument consist of the same characters.
18360
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
   441
     Redefined here, for more efficient comparison of symbols
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
   442
     (which can to be compared using #==).
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   443
     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
   444
     the inherited value compare."
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   445
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   446
%{   /* NOCONTEXT */
18701
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   447
#ifdef __SCHTEAM__
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   448
    if (something.isSymbol()) {
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   449
	return context._RETURN ( self == something ? STObject.True : STObject.False );
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   450
    }
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   451
    if (something.isSTString()) {
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   452
	return context._RETURN ( something.isStringEqual(self) ? STObject.True : STObject.False );
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   453
    }
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   454
    if (something == STObject.Nil) {
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   455
	return context._RETURN_false ( );
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   456
    }
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   457
#else
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   458
    OBJ cls;
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   459
18360
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
   460
    if (something == self) RETURN(true);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   461
    if (! __isNonNilObject(something)) RETURN(false);
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   462
    if ((cls = __qClass(something)) == Symbol) {
18360
21b8e3adff85 can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents: 17516
diff changeset
   463
	RETURN (false);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   464
    }
14658
6c0c3a9eb2c2 class: Symbol
Stefan Vogel <sv@exept.de>
parents: 14651
diff changeset
   465
    if (cls == String || cls == ImmutableString) {
16890
8fa6938075c2 refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents: 16774
diff changeset
   466
	RETURN (strcmp(__stringVal(self), __stringVal(something)) == 0 ? true : false);
345
claus
parents: 329
diff changeset
   467
    }
18701
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   468
#endif
345
claus
parents: 329
diff changeset
   469
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   470
    "fall back; could be a TwoByteString, or a collection of Characters"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   471
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   472
    ^ super = something
427
claus
parents: 384
diff changeset
   473
!
claus
parents: 384
diff changeset
   474
356
claus
parents: 345
diff changeset
   475
identityHash
claus
parents: 345
diff changeset
   476
    "interned symbols can return a better hash key"
claus
parents: 345
diff changeset
   477
13881
f94bfb6c00cd changed: #identityHash
Claus Gittinger <cg@exept.de>
parents: 13690
diff changeset
   478
%{  /* NOCONTEXT */
f94bfb6c00cd changed: #identityHash
Claus Gittinger <cg@exept.de>
parents: 13690
diff changeset
   479
16891
93560afff48f oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents: 16890
diff changeset
   480
    REGISTER unsigned int val; // yes: only 32 bit
356
claus
parents: 345
diff changeset
   481
14651
10791ebb7482 class: Symbol
Stefan Vogel <sv@exept.de>
parents: 13886
diff changeset
   482
    if (__qIsSymbol(self)) {
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   483
	val = __GET_HASH(self);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   484
	/*
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   485
	 * only do it, if I have no standard hash key
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   486
	 * assigned (which can only happen due to a #become:,
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   487
	 * or by creating a symbol uninterned, and interning it
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   488
	 * after it got a hashKey assigned.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   489
	 */
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   490
	if (val == 0) {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   491
	    extern unsigned int __symbolHash(char *);
14651
10791ebb7482 class: Symbol
Stefan Vogel <sv@exept.de>
parents: 13886
diff changeset
   492
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   493
	    val = __symbolHash(__stringVal(self));
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   494
	    // make sure, it fits into a smallInt
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   495
	    val = (val ^ (val >> 30)) & 0x3FFFFFFF;
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   496
	} else {
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   497
	    val = __MAKE_HASH__(val);
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   498
	}
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   499
	RETURN ( __mkSmallInteger(val) );
14651
10791ebb7482 class: Symbol
Stefan Vogel <sv@exept.de>
parents: 13886
diff changeset
   500
    }
356
claus
parents: 345
diff changeset
   501
%}.
14651
10791ebb7482 class: Symbol
Stefan Vogel <sv@exept.de>
parents: 13886
diff changeset
   502
10791ebb7482 class: Symbol
Stefan Vogel <sv@exept.de>
parents: 13886
diff changeset
   503
     ^ super identityHash.
3985
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3659
diff changeset
   504
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3659
diff changeset
   505
     "
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   506
	|hashColl hashSet|
3985
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3659
diff changeset
   507
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   508
	hashColl := OrderedCollection new:20000.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   509
	Symbol allInstancesDo:[:instance |
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   510
	    hashColl add:instance identityHash
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   511
	].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   512
	hashSet := hashColl asSet.
3985
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3659
diff changeset
   513
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   514
	Transcript showCR:'Symbols: ', hashColl size printString,
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   515
			  ' unique hash keys: ', hashSet size printString,
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 19714
diff changeset
   516
			  ' collisions:', (hashColl size - hashSet size) printString.
3985
087595c7629b Tune hash resp. identityHash.
Stefan Vogel <sv@exept.de>
parents: 3659
diff changeset
   517
    "
13881
f94bfb6c00cd changed: #identityHash
Claus Gittinger <cg@exept.de>
parents: 13690
diff changeset
   518
f94bfb6c00cd changed: #identityHash
Claus Gittinger <cg@exept.de>
parents: 13690
diff changeset
   519
    "Modified (comment): / 26-12-2011 / 14:32:10 / cg"
370
claus
parents: 356
diff changeset
   520
!
claus
parents: 356
diff changeset
   521
claus
parents: 356
diff changeset
   522
~= something
claus
parents: 356
diff changeset
   523
    "return true, if the receiver and argument do not consist of the same characters.
11859
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   524
     Redefined here, for more efficient #~= comparison of symbols
370
claus
parents: 356
diff changeset
   525
     (which ought to be compared using #~~).
claus
parents: 356
diff changeset
   526
     If the argument is a symbol, we use a quick pointer compare, instead of
claus
parents: 356
diff changeset
   527
     the inherited value compare."
claus
parents: 356
diff changeset
   528
claus
parents: 356
diff changeset
   529
%{   /* NOCONTEXT */
18701
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   530
#ifdef __SCHTEAM__
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   531
    if (something.isSymbol()) {
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   532
	return context._RETURN ( self == something ? STObject.False : STObject.True );
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   533
    }
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   534
    if (something.isSTString()) {
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   535
	return context._RETURN ( something.isStringEqual(self) ? STObject.False : STObject.True );
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   536
    }
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   537
    if (something == STObject.Nil) {
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   538
	return context._RETURN_true ( );
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   539
    }
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   540
#else
370
claus
parents: 356
diff changeset
   541
    OBJ cls;
claus
parents: 356
diff changeset
   542
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   543
    if (! __isNonNilObject(something)) RETURN(true);    /* cannot be equal */
370
claus
parents: 356
diff changeset
   544
    if ((cls = __qClass(something)) == Symbol) {
16890
8fa6938075c2 refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents: 16774
diff changeset
   545
	RETURN (self == something ? false : true);
370
claus
parents: 356
diff changeset
   546
    }
14658
6c0c3a9eb2c2 class: Symbol
Stefan Vogel <sv@exept.de>
parents: 14651
diff changeset
   547
    if (cls == String || cls == ImmutableString) {
16890
8fa6938075c2 refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents: 16774
diff changeset
   548
	RETURN (strcmp(__stringVal(self), __stringVal(something)) == 0 ? false : true);
370
claus
parents: 356
diff changeset
   549
    }
18701
713eeb421910 steam stuff
Claus Gittinger <cg@exept.de>
parents: 18619
diff changeset
   550
#endif
370
claus
parents: 356
diff changeset
   551
%}.
claus
parents: 356
diff changeset
   552
    "fall back; could be a TwoByteString, or a collection of Characters"
claus
parents: 356
diff changeset
   553
claus
parents: 356
diff changeset
   554
    ^ super ~= something
356
claus
parents: 345
diff changeset
   555
! !
claus
parents: 345
diff changeset
   556
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   557
!Symbol methodsFor:'converting'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   558
23412
be414bc6ccea #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22517
diff changeset
   559
asClass
be414bc6ccea #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22517
diff changeset
   560
    "return the class named after me"
be414bc6ccea #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22517
diff changeset
   561
be414bc6ccea #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22517
diff changeset
   562
    ^ (Smalltalk classNamed:self) ifNil:[ NotFoundError raiseErrorString:'No such class: ',self ]
be414bc6ccea #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22517
diff changeset
   563
be414bc6ccea #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22517
diff changeset
   564
    "
be414bc6ccea #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22517
diff changeset
   565
     #Array asClass 
be414bc6ccea #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22517
diff changeset
   566
     #Foo asClass 
be414bc6ccea #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22517
diff changeset
   567
    "
be414bc6ccea #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22517
diff changeset
   568
!
be414bc6ccea #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22517
diff changeset
   569
23413
cba40e6b7f89 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23412
diff changeset
   570
asClassIfAbsent:exceptionValue
cba40e6b7f89 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23412
diff changeset
   571
    "return the class named after me"
cba40e6b7f89 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23412
diff changeset
   572
cba40e6b7f89 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23412
diff changeset
   573
    ^ (Smalltalk classNamed:self) ifNil:exceptionValue
cba40e6b7f89 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23412
diff changeset
   574
cba40e6b7f89 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23412
diff changeset
   575
    "
cba40e6b7f89 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23412
diff changeset
   576
     #Array asClassIfAbsent:123
cba40e6b7f89 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23412
diff changeset
   577
     #Foo asClassIfAbsent:123 
cba40e6b7f89 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23412
diff changeset
   578
    "
cba40e6b7f89 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23412
diff changeset
   579
cba40e6b7f89 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23412
diff changeset
   580
    "Created: / 10-10-2018 / 00:41:21 / Claus Gittinger"
cba40e6b7f89 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23412
diff changeset
   581
!
cba40e6b7f89 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23412
diff changeset
   582
23920
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   583
asImmutableCollection
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   584
    "I am immutable"
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   585
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   586
    ^ self
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   587
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   588
    "Created: / 15-03-2019 / 13:50:55 / Stefan Vogel"
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   589
!
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   590
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   591
asImmutableString
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   592
    "I am immutable"
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   593
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   594
    ^ self
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   595
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   596
    "Created: / 15-03-2019 / 13:50:44 / Stefan Vogel"
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   597
!
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   598
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   599
asString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   600
    "return a string with printname taken from mine"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   601
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   602
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   603
    OBJ s;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   604
2565
90973ec63991 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2416
diff changeset
   605
    s = __MKSTRING_ST(self);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   606
    if (s != nil) {
11859
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   607
	RETURN (s);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   608
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   609
%}.
5434
c496158fea85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5185
diff changeset
   610
    ^ (String new:(self size))
11859
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   611
	replaceFrom:1 with:self startingAt:1
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   612
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   613
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   614
asSymbol
19467
ac61a8e724f3 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18701
diff changeset
   615
    "Return a unique symbol with the name taken from the receiver's characters.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   616
     Since I am a symbol - just return myself"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   617
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   618
    ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   619
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   620
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   621
asSymbolIfInterned
17185
fa495daf4b1f class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16891
diff changeset
   622
    "If a symbol with the receiver's characters is already known, return it. Otherwise, return nil.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   623
     Since I am a symbol - just return myself"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   624
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   625
    ^ self
21017
04b38ea0c914 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20706
diff changeset
   626
!
04b38ea0c914 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20706
diff changeset
   627
04b38ea0c914 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20706
diff changeset
   628
asSymbolIfInternedOrSelf
04b38ea0c914 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20706
diff changeset
   629
    ^ self
23918
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   630
!
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   631
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   632
beImmutable
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   633
    "I am already immutable"
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   634
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   635
    ^ self
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   636
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   637
    "Created: / 15-03-2019 / 12:46:53 / Stefan Vogel"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   638
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   639
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   640
!Symbol methodsFor:'copying'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   641
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   642
copy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   643
    "return a copy of myself
4729
ae6466d802c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   644
     - reimplemented here since symbols are immutable."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   645
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   646
     ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   647
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   648
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   649
deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   650
    "return a copy of myself
4729
ae6466d802c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   651
     - reimplemented here since symbols are immutable."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   652
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   653
     ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   654
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   655
10950
9979745836ae deepCopy change
ab
parents: 10581
diff changeset
   656
deepCopyUsing:aDictionary postCopySelector:postCopySelector
8383
dea5311899c5 comments in copy methods
Claus Gittinger <cg@exept.de>
parents: 8368
diff changeset
   657
    "return a deep copy of myself
4729
ae6466d802c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   658
     - reimplemented here since symbols are immutable."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   659
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   660
     ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   661
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   662
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   663
shallowCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   664
    "return a copy of myself
10581
77a16d0caa11 comment
Claus Gittinger <cg@exept.de>
parents: 9647
diff changeset
   665
     - reimplemented here since symbols are immutable and unique,
77a16d0caa11 comment
Claus Gittinger <cg@exept.de>
parents: 9647
diff changeset
   666
     so we return the receiver."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   667
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   668
     ^ self
10581
77a16d0caa11 comment
Claus Gittinger <cg@exept.de>
parents: 9647
diff changeset
   669
77a16d0caa11 comment
Claus Gittinger <cg@exept.de>
parents: 9647
diff changeset
   670
    "Modified: / 31-05-2007 / 15:32:30 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   671
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   672
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   673
simpleDeepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   674
    "return a copy of myself
4729
ae6466d802c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   675
     - reimplemented here since symbols are immutable."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   676
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   677
     ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   678
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   679
16154
d1b5d17f1b2b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 15774
diff changeset
   680
!Symbol methodsFor:'evaluation'!
d1b5d17f1b2b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 15774
diff changeset
   681
23849
931471bc4a08 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23838
diff changeset
   682
value:anObject
931471bc4a08 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23838
diff changeset
   683
    "this is sent by collection enumeration methods,
931471bc4a08 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23838
diff changeset
   684
     if a symbol is given instead of a block as loop-block argument"
931471bc4a08 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23838
diff changeset
   685
23918
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   686
    ^ anObject perform:self.
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   687
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   688
    "
24241
7fcbc1f15829 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24121
diff changeset
   689
     this enables the elegant construct:
7fcbc1f15829 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24121
diff changeset
   690
         #(1 2 3 4 5 6 7) collect:#negated
7fcbc1f15829 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24121
diff changeset
   691
      
7fcbc1f15829 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24121
diff changeset
   692
     but also, as a side effect, this ugly thing (if the arg understands the receiver):
7fcbc1f15829 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24121
diff changeset
   693
         #negated value:#(1 2 3 4 5 6 7)
23918
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   694
    "
23849
931471bc4a08 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23838
diff changeset
   695
931471bc4a08 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23838
diff changeset
   696
    "Created: / 07-03-2019 / 17:11:23 / Stefan Vogel"
23918
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   697
    "Modified (format): / 15-03-2019 / 13:39:32 / Stefan Vogel"
24241
7fcbc1f15829 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24121
diff changeset
   698
    "Modified (comment): / 30-05-2019 / 15:01:59 / Claus Gittinger"
23849
931471bc4a08 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23838
diff changeset
   699
!
931471bc4a08 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23838
diff changeset
   700
16154
d1b5d17f1b2b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 15774
diff changeset
   701
value: el value:arg
16890
8fa6938075c2 refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents: 16774
diff changeset
   702
    "this is sent by collection enumeration methods,
16155
c5bae7ca2614 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16154
diff changeset
   703
     if a symbol is given instead of a block as loop-block argument"
16154
d1b5d17f1b2b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 15774
diff changeset
   704
d1b5d17f1b2b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 15774
diff changeset
   705
    ^ el perform:self with:arg.
d1b5d17f1b2b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 15774
diff changeset
   706
d1b5d17f1b2b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 15774
diff changeset
   707
    "
d1b5d17f1b2b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 15774
diff changeset
   708
     this allows us to say:
d1b5d17f1b2b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 15774
diff changeset
   709
d1b5d17f1b2b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 15774
diff changeset
   710
     #(1 2 3 4) with:#(10 20 30 40) collect: #+
d1b5d17f1b2b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 15774
diff changeset
   711
    "
d1b5d17f1b2b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 15774
diff changeset
   712
! !
d1b5d17f1b2b class: Symbol
Claus Gittinger <cg@exept.de>
parents: 15774
diff changeset
   713
14651
10791ebb7482 class: Symbol
Stefan Vogel <sv@exept.de>
parents: 13886
diff changeset
   714
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   715
!Symbol methodsFor:'printing & storing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   716
22516
8fe8242e6c72 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22399
diff changeset
   717
displayString
8fe8242e6c72 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22399
diff changeset
   718
    "return a string used when displaying the receiver in a view;
8fe8242e6c72 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22399
diff changeset
   719
     for example an Inspector. This is usually the same as printString,
8fe8242e6c72 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22399
diff changeset
   720
     but sometimes redefined for a better look."
8fe8242e6c72 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22399
diff changeset
   721
22517
982299841888 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22516
diff changeset
   722
    ^ self storeString
22516
8fe8242e6c72 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22399
diff changeset
   723
8fe8242e6c72 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22399
diff changeset
   724
    "Created: / 31-01-2018 / 09:01:45 / stefan"
8fe8242e6c72 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22399
diff changeset
   725
!
8fe8242e6c72 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22399
diff changeset
   726
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   727
printOn:aStream
4392
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4098
diff changeset
   728
    "append a user printed representation of the receiver to aStream.
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4098
diff changeset
   729
     The format is suitable for a human - not meant to be read back.
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4098
diff changeset
   730
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   731
     In contrast to ST-80, this does return the symbols characters
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   732
     without any leading #. Therefore, you can directly send symbols'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   733
     printStrings to some output device. This is incompatible, but easier
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   734
     to use."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   735
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   736
"/ ST-80 behavior:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   737
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   738
"/  self storeOn:aStream
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   739
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   740
    aStream nextPutAll:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   741
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   742
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   743
printString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   744
    "return a printed representation of the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   745
     In contrast to ST-80, this does return the symbols characters
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   746
     without any leading #. Therefore, you can directly send symbols'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   747
     printStrings to some output device. This is incompatible, but easier
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   748
     to use."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   749
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   750
"/ ST-80 behavior:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   751
"/  ^ self storeString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   752
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   753
    ^ self asString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   754
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   755
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   756
storeOn:aStream
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   757
    "store myself on a stream"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   758
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   759
    aStream nextPutAll:(self storeString)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   760
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   761
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   762
storeString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   763
    "return a String for storing the receiver"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   764
11859
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   765
    |sz "{Class: SmallInteger }"
5941
e194c325bee8 storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents: 5896
diff changeset
   766
     c anyColon|
1125
2bfcfb490837 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1020
diff changeset
   767
7600
5a3fee21c032 #storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents: 7350
diff changeset
   768
    sz := self size.
5a3fee21c032 #storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents: 7350
diff changeset
   769
    (sz ~~ 0 and:[(self at:1) isLetter]) ifTrue:[
11859
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   770
	anyColon := false.
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   771
	2 to:sz do:[:index |
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   772
	    c := self at:index.
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   773
	    c == $: ifTrue:[
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   774
		(index == sz or:[(self at:(index+1)) isLetterOrDigit]) ifFalse:[
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   775
		    ^ '#' , super storeString.
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   776
		].
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   777
		anyColon := true.
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   778
	    ] ifFalse:[
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   779
		c isLetterOrDigit ifFalse:[
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   780
		    ^ '#' , super storeString
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   781
		].
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   782
	    ].
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   783
	].
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   784
	"no colon in symbol or symbol ends with a colon"
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   785
	(anyColon and:[c ~~ $:]) ifFalse:[
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   786
	    ^ '#' , self
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   787
	].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   788
    ].
5896
444e6b63acb5 storeString
Claus Gittinger <cg@exept.de>
parents: 5698
diff changeset
   789
    ^ '#' , super storeString
3285
bd5827c97b21 Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents: 3086
diff changeset
   790
3286
c6987c5f15a8 Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents: 3285
diff changeset
   791
    "
11859
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   792
      #'abc'       storeString
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   793
      #'abc:'      storeString
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   794
      #'abc:def:'  storeString
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   795
      #'abc:def'   storeString
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   796
      #'abc::def'  storeString
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   797
      #'abc &^*'   storeString
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   798
      #'abcdef::'  storeString
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   799
      #'hello''world'  storeString
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   800
      #'' storeString
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   801
      #'''' storeString
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   802
      #'_hello' storeString
752a9509eadf *** empty log message ***
sr
parents: 11819
diff changeset
   803
      #'123'  storeString
3286
c6987c5f15a8 Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents: 3285
diff changeset
   804
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   805
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   806
24026
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   807
!Symbol methodsFor:'private array element printing'!
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   808
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   809
displayArrayElementOn:aStream
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   810
    "Display myself as an Array element on a stream.
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   811
     I am displayed as an array element, so the '#' may be omitted sometimes.
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   812
     Take care for special symbols"
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   813
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   814
    self storeArrayElementOn:aStream.       "storeString is same as printString"
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   815
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   816
    "Created: / 29-03-2019 / 12:00:50 / stefan"
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   817
!
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   818
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   819
printArrayElementOn:aStream
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   820
    "Print myself as an Array element on a stream.
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   821
     I am printed as an array element, so the '#' may be omitted sometimes.
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   822
     Take care for special symbols"
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   823
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   824
    self storeArrayElementOn:aStream.       "storeString is same as printString"
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   825
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   826
    "Created: / 29-03-2019 / 11:56:25 / stefan"
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   827
!
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   828
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   829
storeArrayElementOn:aStream
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   830
    "store myself on a stream.
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   831
     I am stored as an array element, so the '#' may be omitted sometimes.
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   832
     Take care for special symbols"
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   833
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   834
    |storeString|
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   835
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   836
    storeString := self storeString.
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   837
    (self == #true or:[self == #false or:[self == #nil or:[(storeString at:2) == $']]]) ifTrue:[
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   838
	aStream nextPutAll:storeString.
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   839
    ] ifFalse:[
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   840
	aStream nextPutAll:self.
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   841
    ].
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   842
! !
1d8362c3d5ea #UI_ENHANCEMENT by stefan
Stefan Vogel <sv@exept.de>
parents: 23920
diff changeset
   843
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   844
!Symbol methodsFor:'queries'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   845
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   846
species
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   847
    "when copying, or concatenating, return instances of this class"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   848
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   849
    ^ String
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   850
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   851
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   852
!Symbol methodsFor:'system primitives'!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   853
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   854
become:anotherObject
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   855
    "make all references to the receiver become references to anotherObject
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   856
     and vice-versa. For symbols, some special action is required, to
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   857
     correctly handle a become of the global dictionaries.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   858
     Anyway: this is very dangerous - mysterous side-effects are to be
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   859
     expected.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   860
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   861
     Notice: because of the danger here, this method may report an error
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   862
	     in future versions"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   863
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   864
    (Smalltalk includesKey:self) ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   865
	super become:anotherObject.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   866
%{
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   867
	__rehashSystemDictionaries();
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   868
%}.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   869
    ] ifFalse:[
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   870
	super become:anotherObject
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   871
    ]
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   872
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   873
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   874
becomeNil
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   875
    "make all references to the receiver become nil - effectively getting
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   876
     rid of the receiver. For symbols, this is not allowed, if the receiver
7765
c902ef825eeb Fix comment
Stefan Vogel <sv@exept.de>
parents: 7600
diff changeset
   877
     is used as a key in some SystemDictionary.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   878
     This can be a very dangerous operation - be warned.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   879
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   880
     Notice: because of the danger here, this method may report an error
23918
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   881
             in future versions"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   882
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   883
    (Smalltalk includesKey:self) ifTrue:[
23918
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   884
        self noModificationError.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   885
    ] ifFalse:[
23918
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   886
        super becomeNil
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   887
    ]
23918
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   888
95c4a9d8b151 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23849
diff changeset
   889
    "Modified: / 15-03-2019 / 13:30:41 / Stefan Vogel"
13388
0f3e6f1340c8 blocked: #grow:
Claus Gittinger <cg@exept.de>
parents: 13075
diff changeset
   890
!
0f3e6f1340c8 blocked: #grow:
Claus Gittinger <cg@exept.de>
parents: 13075
diff changeset
   891
0f3e6f1340c8 blocked: #grow:
Claus Gittinger <cg@exept.de>
parents: 13075
diff changeset
   892
grow:newSize
13389
5049635eaa51 added: #removeAll
Claus Gittinger <cg@exept.de>
parents: 13388
diff changeset
   893
    "blocked"
13388
0f3e6f1340c8 blocked: #grow:
Claus Gittinger <cg@exept.de>
parents: 13075
diff changeset
   894
13389
5049635eaa51 added: #removeAll
Claus Gittinger <cg@exept.de>
parents: 13388
diff changeset
   895
    self fixedSizeError
13388
0f3e6f1340c8 blocked: #grow:
Claus Gittinger <cg@exept.de>
parents: 13075
diff changeset
   896
0f3e6f1340c8 blocked: #grow:
Claus Gittinger <cg@exept.de>
parents: 13075
diff changeset
   897
    "Created: / 20-06-2011 / 14:57:36 / cg"
13389
5049635eaa51 added: #removeAll
Claus Gittinger <cg@exept.de>
parents: 13388
diff changeset
   898
!
5049635eaa51 added: #removeAll
Claus Gittinger <cg@exept.de>
parents: 13388
diff changeset
   899
5049635eaa51 added: #removeAll
Claus Gittinger <cg@exept.de>
parents: 13388
diff changeset
   900
removeAll
5049635eaa51 added: #removeAll
Claus Gittinger <cg@exept.de>
parents: 13388
diff changeset
   901
    "blocked"
5049635eaa51 added: #removeAll
Claus Gittinger <cg@exept.de>
parents: 13388
diff changeset
   902
5049635eaa51 added: #removeAll
Claus Gittinger <cg@exept.de>
parents: 13388
diff changeset
   903
    self fixedSizeError
5049635eaa51 added: #removeAll
Claus Gittinger <cg@exept.de>
parents: 13388
diff changeset
   904
5049635eaa51 added: #removeAll
Claus Gittinger <cg@exept.de>
parents: 13388
diff changeset
   905
    "Created: / 20-06-2011 / 14:59:02 / cg"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   906
! !
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   907
16774
b543c13298b8 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16735
diff changeset
   908
!Symbol methodsFor:'testing'!
b543c13298b8 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16735
diff changeset
   909
23920
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   910
isImmutable
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   911
    "return true, if the receiver is immutable.
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   912
     Since I am a symbol, return always true"
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   913
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   914
    ^ true
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   915
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   916
    "Created: / 15-03-2019 / 13:58:56 / Stefan Vogel"
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   917
!
2e34d7defd40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23918
diff changeset
   918
16774
b543c13298b8 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16735
diff changeset
   919
isSingleByteString
b543c13298b8 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16735
diff changeset
   920
    "returns true only for strings and immutable strings.
b543c13298b8 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16735
diff changeset
   921
     Must replace foo isMemberOf:String and foo class == String"
b543c13298b8 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16735
diff changeset
   922
b543c13298b8 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16735
diff changeset
   923
    ^ false
21127
258bf1737046 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21017
diff changeset
   924
!
258bf1737046 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21017
diff changeset
   925
258bf1737046 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21017
diff changeset
   926
isSymbol
258bf1737046 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21017
diff changeset
   927
    "return true, if the receiver is some kind of symbol.
258bf1737046 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21017
diff changeset
   928
     Since I am a symbol, return always true"
258bf1737046 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21017
diff changeset
   929
258bf1737046 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21017
diff changeset
   930
    ^ true
16774
b543c13298b8 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16735
diff changeset
   931
! !
b543c13298b8 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16735
diff changeset
   932
4651
18a6ac30b36f added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4530
diff changeset
   933
!Symbol methodsFor:'tracing'!
18a6ac30b36f added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4530
diff changeset
   934
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4654
diff changeset
   935
traceInto:aRequestor level:level from:referrer
4651
18a6ac30b36f added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4530
diff changeset
   936
    "double dispatch into tracer, passing my type implicitely in the selector"
18a6ac30b36f added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4530
diff changeset
   937
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4654
diff changeset
   938
    ^ aRequestor traceSymbol:self level:level from:referrer
4651
18a6ac30b36f added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4530
diff changeset
   939
18a6ac30b36f added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4530
diff changeset
   940
18a6ac30b36f added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4530
diff changeset
   941
! !
18a6ac30b36f added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4530
diff changeset
   942
8395
6bd97113cb4c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
   943
!Symbol methodsFor:'visiting'!
6bd97113cb4c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
   944
6bd97113cb4c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
   945
acceptVisitor:aVisitor with:aParameter
16735
1bb1692ca886 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16714
diff changeset
   946
    "dispatch for visitor pattern; send #visitSymbol:with: to aVisitor"
8395
6bd97113cb4c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
   947
6bd97113cb4c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
   948
    ^ aVisitor visitSymbol:self with:aParameter
6bd97113cb4c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
   949
! !
6bd97113cb4c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8383
diff changeset
   950
632
31498e8b424c version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   951
!Symbol class methodsFor:'documentation'!
31498e8b424c version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   952
16155
c5bae7ca2614 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16154
diff changeset
   953
version
18619
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   954
    ^ '$Header$'
16155
c5bae7ca2614 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16154
diff changeset
   955
!
c5bae7ca2614 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 16154
diff changeset
   956
13423
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   957
version_CVS
18619
1f307a4b4875 class: Symbol
Claus Gittinger <cg@exept.de>
parents: 18360
diff changeset
   958
    ^ '$Header$'
12473
828e275ddf8b change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11859
diff changeset
   959
!
828e275ddf8b change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11859
diff changeset
   960
13423
716d670cb422 Jan's changes
vrany
parents: 13389
diff changeset
   961
version_SVN
15524
74a35ef1db4d class: Symbol
Stefan Vogel <sv@exept.de>
parents: 14658
diff changeset
   962
    ^ '$ Id: Symbol.st 10648 2011-06-23 15:55:10Z vranyj1  $'
632
31498e8b424c version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   963
! !
21017
04b38ea0c914 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20706
diff changeset
   964