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