Symbol.st
changeset 159 514c749165c3
parent 95 d22739a0c6e9
child 189 d430ee92430c
equal deleted inserted replaced
158:be947d4e7fb2 159:514c749165c3
     1 "
     1 "
     2  COPYRIGHT (c) 1988 by Claus Gittinger
     2  COPYRIGHT (c) 1988 by Claus Gittinger
     3               All Rights Reserved
     3 	      All Rights Reserved
     4 
     4 
     5  This software is furnished under a license and may be used
     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
     6  only in accordance with the terms of that license and with the
     7  inclusion of the above copyright notice.   This software may not
     7  inclusion of the above copyright notice.   This software may not
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
    17        category:'Collections-Text'
    17        category:'Collections-Text'
    18 !
    18 !
    19 
    19 
    20 Symbol comment:'
    20 Symbol comment:'
    21 COPYRIGHT (c) 1988 by Claus Gittinger
    21 COPYRIGHT (c) 1988 by Claus Gittinger
    22               All Rights Reserved
    22 	      All Rights Reserved
    23 
    23 
    24 $Header: /cvs/stx/stx/libbasic/Symbol.st,v 1.11 1994-08-05 01:02:49 claus Exp $
    24 $Header: /cvs/stx/stx/libbasic/Symbol.st,v 1.12 1994-10-10 00:28:50 claus Exp $
    25 '!
    25 '!
    26 
    26 
    27 !Symbol class methodsFor:'documentation'!
    27 !Symbol class methodsFor:'documentation'!
    28 
    28 
    29 copyright
    29 copyright
    30 "
    30 "
    31  COPYRIGHT (c) 1988 by Claus Gittinger
    31  COPYRIGHT (c) 1988 by Claus Gittinger
    32               All Rights Reserved
    32 	      All Rights Reserved
    33 
    33 
    34  This software is furnished under a license and may be used
    34  This software is furnished under a license and may be used
    35  only in accordance with the terms of that license and with the
    35  only in accordance with the terms of that license and with the
    36  inclusion of the above copyright notice.   This software may not
    36  inclusion of the above copyright notice.   This software may not
    37  be provided or otherwise made available to, or used by, any
    37  be provided or otherwise made available to, or used by, any
    40 "
    40 "
    41 !
    41 !
    42 
    42 
    43 version
    43 version
    44 "
    44 "
    45 $Header: /cvs/stx/stx/libbasic/Symbol.st,v 1.11 1994-08-05 01:02:49 claus Exp $
    45 $Header: /cvs/stx/stx/libbasic/Symbol.st,v 1.12 1994-10-10 00:28:50 claus Exp $
    46 "
    46 "
    47 !
    47 !
    48 
    48 
    49 documentation
    49 documentation
    50 "
    50 "
    77 intern:aString
    77 intern:aString
    78     "return a unique symbol with printname taken from the String-argument"
    78     "return a unique symbol with printname taken from the String-argument"
    79 
    79 
    80 %{  /* NOCONTEXT */
    80 %{  /* NOCONTEXT */
    81     if (__isSymbol(aString)) {
    81     if (__isSymbol(aString)) {
    82         RETURN (aString);
    82 	RETURN (aString);
    83     }
    83     }
    84     if (__isString(aString)) {
    84     if (__isString(aString)) {
    85         RETURN ( _MKSYMBOL(_stringVal(aString), (OBJ *)0, __context) );
    85 	RETURN ( _MKSYMBOL(_stringVal(aString), (OBJ *)0, __context) );
    86     }
    86     }
    87 %}
    87 %}
    88 .
    88 .
    89     ^ self mustBeString
    89     ^ self mustBeString
    90 !
    90 !
    98      names are unique (for example by including the classes name as a prefix-string)."
    98      names are unique (for example by including the classes name as a prefix-string)."
    99 
    99 
   100     |newSym len|
   100     |newSym len|
   101 
   101 
   102     aString knownAsSymbol ifTrue:[
   102     aString knownAsSymbol ifTrue:[
   103         ^ aString asSymbol
   103 	^ aString asSymbol
   104     ].
   104     ].
   105 
   105 
   106     "
   106     "
   107      create a new uninterned instance first
   107      create a new uninterned instance first
   108     "
   108     "
   131     "for ST-80 compatibility - if the argument, aString is known
   131     "for ST-80 compatibility - if the argument, aString is known
   132      as Symbol, evaluate the block with the corresponding symbol
   132      as Symbol, evaluate the block with the corresponding symbol
   133      as argument and return true; otherwise return false"
   133      as argument and return true; otherwise return false"
   134 
   134 
   135     aString knownAsSymbol ifTrue:[
   135     aString knownAsSymbol ifTrue:[
   136         trueBlock value:(aString asSymbol).
   136 	trueBlock value:(aString asSymbol).
   137         ^ true
   137 	^ true
   138     ].
   138     ].
   139     ^ false
   139     ^ false
   140 !
   140 !
   141 
   141 
   142 hasInterned:aString
   142 hasInterned:aString
   150 
   150 
   151 basicAt:index put:something
   151 basicAt:index put:something
   152     "report an error if interned - interned symbols may not be changed."
   152     "report an error if interned - interned symbols may not be changed."
   153 
   153 
   154     self knownAsSymbol ifTrue:[
   154     self knownAsSymbol ifTrue:[
   155         self error:'symbols may not be changed'.
   155 	self error:'symbols may not be changed'.
   156         ^ something
   156 	^ something
   157     ].
   157     ].
   158     "
   158     "
   159      uninterned - allow change
   159      uninterned - allow change
   160     "
   160     "
   161     ^ super basicAt:index put:something
   161     ^ super basicAt:index put:something
   162 ! !
   162 ! !
   163 
   163 
   164 !Symbol methodsFor:'copying'!
   164 !Symbol methodsFor:'copying'!
   165 
   165 
       
   166 copy
       
   167     "return a copy of myself
       
   168      - reimplemented here since symbols are unique"
       
   169 
       
   170      ^ self
       
   171 !
       
   172 
       
   173 shallowCopy
       
   174     "return a copy of myself
       
   175      - reimplemented here since symbols are unique"
       
   176 
       
   177      ^ self
       
   178 !
       
   179 
       
   180 deepCopy
       
   181     "return a copy of myself
       
   182      - reimplemented here since symbols are unique"
       
   183 
       
   184      ^ self
       
   185 !
       
   186 
   166 deepCopyUsing:aDictionary
   187 deepCopyUsing:aDictionary
   167     "return a copy of myself
       
   168      - reimplemented here since symbols are unique"
       
   169 
       
   170      ^ self
       
   171 !
       
   172 
       
   173 deepCopy
       
   174     "return a copy of myself
   188     "return a copy of myself
   175      - reimplemented here since symbols are unique"
   189      - reimplemented here since symbols are unique"
   176 
   190 
   177      ^ self
   191      ^ self
   178 !
   192 !
   212      correctly handle a become of the global dictionaries.
   226      correctly handle a become of the global dictionaries.
   213      Anyway: this is very dangerous - mysterous side-effects are to be
   227      Anyway: this is very dangerous - mysterous side-effects are to be
   214      expected.
   228      expected.
   215 
   229 
   216      Notice: because of the danger here, this method may report an error
   230      Notice: because of the danger here, this method may report an error
   217              in future versions"
   231 	     in future versions"
   218 
   232 
   219     (Smalltalk includesKey:self) ifTrue:[
   233     (Smalltalk includesKey:self) ifTrue:[
   220         super become:anotherObject.
   234 	super become:anotherObject.
   221 %{
   235 %{
   222         __rehashSystemDictionaries();
   236 	__rehashSystemDictionaries();
   223 %}.
   237 %}.
   224     ] ifFalse:[
   238     ] ifFalse:[
   225         super become:anotherObject
   239 	super become:anotherObject
   226     ]
   240     ]
   227 !
   241 !
   228 
   242 
   229 becomeNil
   243 becomeNil
   230     "make all references to the receiver become nil - effectively getting
   244     "make all references to the receiver become nil - effectively getting
   231      rid of the receiver. For symbols, this is not allowed, if the receiver
   245      rid of the receiver. For symbols, this is not allowed, if the receiver
   232      is used as a key in some SytemDictionary.
   246      is used as a key in some SytemDictionary.
   233      This can be a very dangerous operation - be warned.
   247      This can be a very dangerous operation - be warned.
   234 
   248 
   235      Notice: because of the danger here, this method may report an error
   249      Notice: because of the danger here, this method may report an error
   236              in future versions"
   250 	     in future versions"
   237 
   251 
   238     (Smalltalk includesKey:self) ifTrue:[
   252     (Smalltalk includesKey:self) ifTrue:[
   239         self primitiveFailed
   253 	self primitiveFailed
   240     ] ifFalse:[
   254     ] ifFalse:[
   241         super becomeNil
   255 	super becomeNil
   242     ]
   256     ]
   243 ! !
   257 ! !
   244 
   258 
   245 !Symbol class methodsFor:'binary storage'!
   259 !Symbol class methodsFor:'binary storage'!
   246 
   260 
   269 
   283 
   270 storeString
   284 storeString
   271     "return a String for storing the receiver"
   285     "return a String for storing the receiver"
   272 
   286 
   273     (self at:1) isLetter ifTrue:[
   287     (self at:1) isLetter ifTrue:[
   274         2 to:self size do:[:index |
   288 	2 to:self size do:[:index |
   275             (self at:index) isAlphaNumeric ifFalse:[
   289 	    (self at:index) isLetterOrDigit ifFalse:[
   276                 ^ '#''' , self , ''''
   290 		^ '#''' , self , ''''
   277             ].
   291 	    ].
   278         ].
   292 	].
   279         ^ '#' , self
   293 	^ '#' , self
   280     ].
   294     ].
   281     ^ '#''' , self , ''''
   295     ^ '#''' , self , ''''
   282 !
   296 !
   283 
   297 
   284 storeOn:aStream
   298 storeOn:aStream