2 summary:: fixed size collection
3 related:: Reference/Literals, Classes/List
4 categories:: Collections>Ordered
7 Arrays are ArrayedCollections whose slots may contain any object. Arrays have a fixed maximum size beyond which they cannot grow. For expandable arrays, use the link::Classes/List:: class.
9 For Arrays, the code::add:: method may or may not return the same Array object. It will add the argument to the receiver if there is space, otherwise it returns a new Array object with the argument added. Thus the proper usage of code::add:: with an Array is to always assign the result as follows:
13 This allows an efficient use of resources, only growing the array when it needs to. The List class manages the Array for you, and in many cases is more suitable.
15 Elements can be put into an existing slot with code::a.put(2,obj):: and accessed with
16 code::a.at(2):: or code::a[2]::
18 See link::Classes/ArrayedCollection:: for the principal methods: at, put, clipAt, wrapAt, etc...
20 Literal Arrays can be created at compile time, and are very efficient. See link::Reference/Literals:: for information.
25 Create a new array with size 0 that can grow up to the fixed size.
27 The maximum size of the array.
30 Create a new array with all slots filled with nils.
32 The size of the array.
35 Create a new Array whose slots are filled with the given arguments.
36 This is the same as the method in ArrayedCollection, but is reimplemented here to be more efficient.
38 Array.with(7, 'eight', 9).postln;
44 Returns a new Array whose elements are reversed. The receiver is unchanged.
53 Returns a new Array whose elements have been scrambled. The receiver is unchanged.
55 [1, 2, 3, 4, 5, 6].scramble.postln;
59 Return a new Array which is the receiver made into a palindrome.
60 The receiver is unchanged.
62 [1, 2, 3, 4].mirror.postln;
66 Return a new Array which is the receiver made into a palindrome with the last element removed.
67 This is useful if the list will be repeated cyclically, the first element will not get played twice.
68 The receiver is unchanged.
70 [1, 2, 3, 4].mirror1.postln;
74 Return a new Array which is the receiver concatenated with a reversal of itself.
75 The center element is duplicated. The receiver is unchanged.
77 [1, 2, 3, 4].mirror2.postln;
81 Return a new Array whose elements are repeated n times. The receiver is unchanged.
83 [1, 2, 3].stutter(2).postln;
89 Return a new Array whose elements are in rotated order. The receiver is unchanged.
91 [1, 2, 3, 4, 5].rotate(1).postln;
92 [1, 2, 3, 4, 5].rotate(-1).postln;
93 [1, 2, 3, 4, 5].rotate(3).postln;
96 Number of elements to rotate. Negative n values rotate left, postive n values
100 Return a new Array whose elements have been reordered via one of 10 "counting" algorithms.
101 Run the examples to see the algorithms.
104 [1, 2, 3, 4].pyramid(i + 1).postcs;
108 Choose counting algorithm. The algorithms are numbered 1 through 10.
111 Like pyramid, but keep the resulting values grouped in subarrays.
114 [1, 2, 3, 4].pyramid(1).postln;
115 [1, 2, 3, 4].pyramidg(1).postln;
119 Return a new Array of length maxlen with the items partly repeated (random choice of given probability).
122 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].sputter(0.5, 16).postln;
123 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].sputter(0.8, 8).postln;
125 argument::probability
126 Probability of repeat.
128 The length of the new Array.
131 Returns a new Array whose elements are interlaced sequences of the elements of the receiver's subcollections, up to size length. The receiver is unchanged.
133 x = [ [1, 2, 3], 6, List["foo", 'bar']];
140 Returns a new Array whose elements are the nthPermutation of the elements of the receiver. The receiver is unchanged.
143 6.do({|i| x.permute(i).postln;});
147 Returns a new Array whose elements contain all possible combinations of the receiver's subcollections.
149 [[1, 2, 3, 4, 5], [10, 20, 30]].allTuples;
150 [[1, 2, 3, 4, 5], [10, 20, 30], [5, 6]].allTuples;
154 Returns a new Array whose elements are repeated sequences of the receiver, up to size length. The receiver is unchanged.
156 x = [ 1, 2, 3, "foo", 'bar' ];
163 Same as wrapExtend but the sequences fold back on the list elements.
172 Same as wrapExtend but the sequences "clip" (return their last element) rather than wrapping.
181 Return a new Array whose elements are repeated subsequences from the receiver.
182 Easier to demonstrate than explain.
184 [1, 2, 3, 4, 5, 6].slide(3, 1).postcs;
185 [1, 2, 3, 4, 5, 6].slide(3, 2).postcs;
186 [1, 2, 3, 4, 5, 6].slide(4, 1).postcs;
190 Shift the values of the array n steps to the right (n positive) or to the left(n negative),
191 dropping the excess and filling empty space with zero.
193 [1, 2, 3, 4, 5, 6].shift(3).postln;
194 [1, 2, 3, 4, 5, 6].shift(-3).postln;
197 method::containsSeqColl
198 Returns true if the receiver Array contains any instance of SequenceableCollection
200 [1, 2, 3, 4].containsSeqColl.postln
201 [1, 2, [3], 4].containsSeqColl.postln
205 Returns all possible combinations of the array's elements.
207 [1, 2, 3].powerset.postln
208 [1, 2, 3].powerset.sort({ |a, b| a.size > b.size }); // sort by size, big first
209 [1, 2, 3].powerset.sort({ |a, b| a.size > b.size }).reverse; // by size, small first
211 powerset is also supported in Collection:
213 Set[1, 2, 3].powerset;
214 List[1, 2, 3].powerset
215 (a: 1, b: 2, c: 3).powerset;
219 Given an array of symbols, this returns an array of pairs of (symbol, value) from the current environment.
220 This can then be used as arguments for a Synth, or in an OSC message.
222 e = (freq: 340, amp: 0.001, strangeness: 0.85);
224 [\amp, \taste, \strangeness].envirPairs;
229 Invert rows and colums in a two dimensional Array (turn inside out).
230 See also: Function, SequenceableCollection.
232 [[1, 2, 3], [4, 5, 6]].flop;
233 [[1, 2, 3], [4, 5, 6], [7, 8]].flop; // shorter array wraps
234 [].flop; // result is always 2-d.
237 method::multiChannelExpand
238 Used by UGens to perform multi channel expansion. Same as flop.
241 Some UGens return Arrays of OutputProxy when instantiated. This method allows you to
242 get at the source UGen.
250 Used within Routines and assumes an array of functions, from which subroutines are created. The subroutines are played while the outer Routine carries on. The join parameter expresses after how many subroutines complete the outer Routine is allowed to go on. By default this happens after all subroutines have completed.
252 // an array of routine functions:
255 { 1.wait; \done_one.postln },
256 { 0.5.wait; \done_two.postln },
257 { 0.2.wait; \done_three.postln }
264 a.fork(0); \doneAll.postln;
271 a.fork(1); \doneAll.postln;
277 "join = a.size (default).".postcln;
278 a.fork; \doneAll.postln;
282 poll(trig, label, trigid)
283 apply an array of Poll units to an array of UGens (see those helpfiles for more details).
288 SinOsc.ar([0.1, 0.2], 0).poll * 0.1
291 x.trace; // By tracing the Synth you can see the two Poll units we created
296 apply an array of Dpoll units to an array of UGens (see those helpfiles for more details).
298 method::atIdentityHash
299 This method is used by IdentitySet to search for a key among its members.
301 method::atIdentityHashInPairs
302 This method is used by IdentityDictionary to search for a key among its members.
305 Returns a string representing the Array. May not be compileable due to ellision (...) of excessive arguments.
307 method::asCompileString
308 Returns a string that will compile to return an Array equal to the receiver.
310 method::isValidUGenInput
311 Returns true. Arrays are valid UGen inputs.
314 Returns the OSC measse as an Int8Array. Receiver must be a bundle.
316 [0.1, [\s_new, \default, -1, 1, 1, \freq, 1961]].asRawOSC;