34 " |
34 " |
35 ! |
35 ! |
36 |
36 |
37 documentation |
37 documentation |
38 " |
38 " |
39 Instances of Array store general objects; the arrays size is fixed, |
39 Instances of Array store general objects; |
40 therefore add:/remove: are not allowed. |
40 an array's size is fixed, therefore add:/remove: are not allowed. |
41 (actually, #add: is implemented for compatibility with smalltalks which |
41 (actually, #add: is implemented for compatibility with smalltalks which |
42 provide it, but it is very slow and outputs an annoying warning message ...) |
42 provide it, but it is very slow and outputs an annoying warning message...) |
43 |
43 |
44 Access to the individual elements is via an integer index, |
44 Access to the individual elements is via an integer index, |
45 using the well-known access messages #at: and #at:put:. |
45 using the well-known access messages #at: and #at:put:. |
46 |
46 |
47 Since Arrays are used very often in the system (either directly or a data-container |
47 Since Arrays are used very often in the system (either directly or a data-container |
49 them as primitives. Also, the compiler inline-codes some operations |
49 them as primitives. Also, the compiler inline-codes some operations |
50 (especially: the above accessing messages). |
50 (especially: the above accessing messages). |
51 |
51 |
52 Notice that Array is a built-in class |
52 Notice that Array is a built-in class |
53 (i.e. the VM knows about its representation). |
53 (i.e. the VM knows about its representation). |
54 Therefore it is NOT possible to add named instance variables or change |
54 Therefore it is NOT possible to add named instance variables or change Arrays inheritance. |
55 Arrays inheritance. |
|
56 However, subclassing is allowed of course |
55 However, subclassing is allowed of course |
57 - even with added named instance variables. |
56 - even with added named instance variables. |
58 |
57 |
59 Literal arrays (i.e. array-constants) are entered in source as: |
58 Literal arrays (i.e. array-constants) are entered in source as: |
60 |
59 |
61 #( element1 element2 ... element-n) |
60 #( element1 element2 ... element-N) |
62 |
61 |
63 where each element must be itself a literal constant. |
62 where each element must be itself a literal constant. |
64 Array, symbol and byteArray constants within an array can be written |
63 Array, symbol and byteArray constants within an array can be written |
65 without the initial #-character. |
64 without the initial #-character. |
66 In addition, true, false and nil are also allowed as array-literal. |
65 In addition, true, false and nil are also allowed as array-literal. |
71 #('foo' #(1 2) #foo) -> 3 elements: a String, another array and a symbol |
70 #('foo' #(1 2) #foo) -> 3 elements: a String, another array and a symbol |
72 #('foo' (1 2) foo) -> same as above |
71 #('foo' (1 2) foo) -> same as above |
73 #(nil true #true) -> 3 elements: nil, true and a symbol (watch out) |
72 #(nil true #true) -> 3 elements: nil, true and a symbol (watch out) |
74 #(two [3 3 3] (4 4 4)) -> 3 elements: a symbol, a byteArray and another array |
73 #(two [3 3 3] (4 4 4)) -> 3 elements: a symbol, a byteArray and another array |
75 |
74 |
|
75 Also, a syntactic sugar piece allows for Array instances to be created dynamcially |
|
76 at runtime with the brace syntax: |
|
77 |
|
78 { expr1 . expr2 . ... . expr-N } |
|
79 |
|
80 where each expr-i evaluates to an element of the new array instance. |
|
81 Notice that the expressions are separated by a period. |
|
82 Semantically, this is equivalent to ``Array with:expr1 with:expr2 ... with:expr-N'' |
|
83 Examples: |
|
84 { 1 . 2 . 3 } -> a new 3 element array; similar to #( 1 2 3 ), |
|
85 but in contrast, a new array instance is created |
|
86 { |
|
87 { 'foo' . [ Transcript showCR:'foo' ] } . |
|
88 { 'bar' . [ Transcript showCR:'bar' ] } |
|
89 { 'baz' . [ Transcript showCR:'baz' ] } |
|
90 } |
|
91 -> a new 3 element array, consisting of 3 new |
|
92 2-element array instances, consisting of a string |
|
93 and a block each |
|
94 |
76 [memory requirements:] |
95 [memory requirements:] |
77 OBJ-HEADER + (size * ptr-size) |
96 OBJ-HEADER + (size * ptr-size) |
78 |
97 |
79 [warning:] |
98 [warning:] |
80 read the warning about 'growing fixed size collection' |
99 read the warning about 'growing fixed size collection' |
81 in ArrayedCollection's documentation |
100 in ArrayedCollection's documentation |
82 |
101 |
83 [author:] |
102 [author:] |
84 Claus Gittinger |
103 Claus Gittinger |
85 |
104 |
86 [see also:] |
105 [see also:] |
87 OrderedCollection |
106 OrderedCollection |
88 ByteArray FloatArray DoubleArray |
107 ByteArray FloatArray DoubleArray |
89 String |
108 String |
90 " |
109 " |
91 ! ! |
110 ! ! |
92 |
111 |
93 !Array class methodsFor:'instance creation'! |
112 !Array class methodsFor:'instance creation'! |
94 |
113 |