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