![]() |
Smalltalk/X WebserverDocumentation of class 'ImmutableArray': |
|
|
Class: ImmutableArrayInheritance:Object | +--Collection | +--SequenceableCollection | +--ArrayedCollection | +--Array | +--ImmutableArray
Description:By default, array literals in smalltalk are mutable objects. That may lead to some subtle (and hard to find errors), if some method passes a literal array constant as argument to someone else, who changes the array using at:put: like messages. Since the array object is kept in the first methods literals, the array constant has now been changed without having the method's sourcecode reflect this. Thus, the method will behave differently from what its source may make you think. To help finding this kind of 'feature/bug', the compiler can be configured to create instances of this ImmutableArray instead of Arrays for array literals. Instances of ImmutableArray catch storing accesses and enter the debugger. Although useful, this feature is disabled by default for compatibility to other smalltalk implementations. (Also, if turned on, this makes inspecting array literals entered in a workspace somewhat strange: you cannot modify it any longer). Turn the ImmutableArray feature on by setting the Parsers class variable 'ArraysAreImmutable' to true or use the new launchers settings menu. This class should be used only by the compiler. ATTENTION: there may be still code around which checks for explicit class being Array (both in Smalltalk and in primitive code). All code like foo 'class == Array' or '__isArray' will not work with ImmutableArrays; consider using '__isArrayLike'. A somewhat better approach would be to either add a flag to the object (mutability) and check this dynamically (expensive) or to place immutable objects into a readonly memory segment (the good solution). We will eventually implement the second in the future... Related information:ImmutableString ImmutableByteArray Parser Scanner Class protocol:queries
Instance protocol:accessing
|
|
|
ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Wed, 06 Dec 2023 04:16:58 GMT
|