1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
1
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
String subclass:#Symbol
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Collections-Text'
|
|
18 |
!
|
|
19 |
|
|
20 |
Symbol comment:'
|
|
21 |
|
5
|
22 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
1
|
23 |
All Rights Reserved
|
|
24 |
|
|
25 |
Symbols represent unique strings - every symbol with same printString
|
|
26 |
exists exactly once in the system; Symbols are used for selectors, global
|
|
27 |
variable-keys etc.
|
|
28 |
|
68
|
29 |
$Header: /cvs/stx/stx/libbasic/Symbol.st,v 1.8 1994-03-30 09:37:04 claus Exp $
|
1
|
30 |
'!
|
|
31 |
|
|
32 |
!Symbol class methodsFor:'instance creation'!
|
|
33 |
|
62
|
34 |
XXXbasicNew:size
|
1
|
35 |
"catch instance creation - symbols are not created with new"
|
|
36 |
|
|
37 |
self error:'symbols may not be created with new:'
|
|
38 |
!
|
|
39 |
|
62
|
40 |
basicNew:size
|
|
41 |
"redefined to return a string instead of a symbol -
|
|
42 |
this allows all copy methods inherited from String to
|
|
43 |
return strings containing the symbols characters.
|
|
44 |
Real symbols are only created with intern: or asSymbol."
|
|
45 |
|
|
46 |
^ String new:size
|
|
47 |
!
|
|
48 |
|
|
49 |
new:size
|
|
50 |
"redefined to return a string instead of a symbol -
|
|
51 |
this allows all copy methods inherited from String to
|
|
52 |
return strings containing the symbols characters.
|
|
53 |
Real symbols are only created with intern: or asSymbol."
|
|
54 |
|
|
55 |
^ String new:size
|
|
56 |
!
|
|
57 |
|
1
|
58 |
intern:aString
|
|
59 |
"return a unique symbol with printname taken from the String-argument"
|
|
60 |
|
62
|
61 |
%{ /* NOCONTEXT */
|
|
62 |
if (__isSymbol(aString)) {
|
|
63 |
RETURN (aString);
|
|
64 |
}
|
|
65 |
if (__isString(aString)) {
|
1
|
66 |
RETURN ( _MKSYMBOL(_stringVal(aString), (OBJ *)0, __context) );
|
|
67 |
}
|
|
68 |
%}
|
|
69 |
.
|
|
70 |
^ self mustBeString
|
|
71 |
!
|
|
72 |
|
|
73 |
internCharacter:aCharacter
|
|
74 |
"return a unique symbol with printname taken from the Character-argument"
|
|
75 |
|
|
76 |
^ self intern:(aCharacter asString)
|
|
77 |
! !
|
|
78 |
|
|
79 |
!Symbol class methodsFor:'queries'!
|
|
80 |
|
|
81 |
hasInterned:aString ifTrue:trueBlock
|
|
82 |
"for ST-80 compatibility - if the argument, aString is known
|
|
83 |
as Symbol, evaluate the block with the corresponding symbol
|
|
84 |
as argument and return true; otherwise return false"
|
|
85 |
|
|
86 |
aString knownAsSymbol ifTrue:[
|
|
87 |
trueBlock value:(aString asSymbol).
|
|
88 |
^ true
|
|
89 |
].
|
|
90 |
^ false
|
|
91 |
! !
|
|
92 |
|
|
93 |
!Symbol methodsFor:'accessing'!
|
|
94 |
|
|
95 |
basicAt:index put:something
|
|
96 |
"report an error - symbols may not be changed"
|
|
97 |
|
|
98 |
self error:'symbols may not be changed'
|
|
99 |
!
|
|
100 |
|
|
101 |
at:index put:something
|
|
102 |
"report an error - symbols may not be changed"
|
|
103 |
|
|
104 |
self error:'symbols may not be changed'
|
|
105 |
! !
|
|
106 |
|
|
107 |
!Symbol methodsFor:'copying'!
|
|
108 |
|
13
|
109 |
deepCopyUsing:aDictionary
|
|
110 |
"return a copy of myself
|
|
111 |
- reimplemented here since symbols are unique"
|
|
112 |
|
|
113 |
^ self
|
|
114 |
!
|
|
115 |
|
1
|
116 |
deepCopy
|
|
117 |
"return a copy of myself
|
|
118 |
- reimplemented here since symbols are unique"
|
|
119 |
|
|
120 |
^ self
|
13
|
121 |
!
|
|
122 |
|
|
123 |
simpleDeepCopy
|
|
124 |
"return a copy of myself
|
|
125 |
- reimplemented here since symbols are unique"
|
|
126 |
|
|
127 |
^ self
|
1
|
128 |
! !
|
|
129 |
|
|
130 |
!Symbol methodsFor:'converting'!
|
|
131 |
|
|
132 |
asString
|
|
133 |
"return a string with printname taken from mine"
|
|
134 |
|
|
135 |
^ self printString
|
|
136 |
!
|
|
137 |
|
|
138 |
asSymbol
|
|
139 |
"I am a symbol - just return myself"
|
|
140 |
|
|
141 |
^ self
|
|
142 |
! !
|
|
143 |
|
|
144 |
!Symbol methodsFor:'misc'!
|
|
145 |
|
|
146 |
species
|
|
147 |
^ String
|
|
148 |
! !
|
|
149 |
|
2
|
150 |
!Symbol class methodsFor:'binary storage'!
|
|
151 |
|
|
152 |
binaryDefinitionFrom: stream manager: manager
|
|
153 |
^ self intern: (super binaryDefinitionFrom: stream manager: manager)
|
|
154 |
! !
|
|
155 |
|
1
|
156 |
!Symbol methodsFor:'printing & storing'!
|
|
157 |
|
|
158 |
printString
|
|
159 |
%{
|
|
160 |
RETURN ( _MKSTRING(_stringVal(self) COMMA_CON) );
|
|
161 |
%}
|
|
162 |
!
|
|
163 |
|
|
164 |
printOn:aStream
|
|
165 |
"aStream nextPut:$#."
|
68
|
166 |
aStream nextPutAll:self "(self printString)"
|
1
|
167 |
!
|
|
168 |
|
|
169 |
displayString
|
10
|
170 |
"return a string for displaying the receiver"
|
|
171 |
|
1
|
172 |
^ self storeString
|
|
173 |
!
|
|
174 |
|
|
175 |
storeString
|
10
|
176 |
"return a String for storing the receiver"
|
1
|
177 |
|
10
|
178 |
(self at:1) isLetter ifTrue:[
|
|
179 |
2 to:self size do:[:index |
|
|
180 |
(self at:index) isAlphaNumeric ifFalse:[
|
|
181 |
^ '#''' , self , ''''
|
|
182 |
].
|
|
183 |
].
|
|
184 |
^ '#' , self
|
|
185 |
].
|
2
|
186 |
^ '#''' , self , ''''
|
1
|
187 |
!
|
|
188 |
|
|
189 |
storeOn:aStream
|
10
|
190 |
"store myself on a stream"
|
|
191 |
|
|
192 |
aStream nextPutAll:(self storeString)
|
1
|
193 |
! !
|