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 strong::Literal Arrays:: can be created at compile time, and are very efficient. See link::Reference/Literals:: for information.
11 For handling strong::multidimensional arrays::, there are specific methods which are covered in the helpfile link::Guides/J-concepts-in-SC::.
14 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:
18 This allows an efficient use of resources, only growing the array when it needs to. The link::Classes/List:: class manages the Array internally, and in many cases is more suitable.
21 Elements can be put into an existing slot with code::a.put(2,obj):: and accessed with
22 code::a.at(2):: or code::a[2]::
24 See link::Classes/ArrayedCollection:: for the principal methods: at, put, clipAt, wrapAt, etc...
30 Create a new array with size 0 that can grow up to the fixed size.
32 The maximum size of the array.
35 Create a new array with all slots filled with nils.
37 The size of the array.
40 Create a new Array whose slots are filled with the given arguments.
41 This is the same as the method in ArrayedCollection, but is reimplemented here to be more efficient.
43 Array.with(7, 'eight', 9).postln;
46 copymethod:: Collection *fill
48 copymethod:: Collection *fill2D
50 copymethod:: Collection *fillND
52 copymethod:: Collection *newFrom
54 copymethod:: ArrayedCollection *geom
56 copymethod:: ArrayedCollection *series
58 copymethod:: ArrayedCollection *iota
60 copymethod:: Collection *interpolation
62 copymethod:: Collection *rand
64 copymethod:: Collection *rand2
66 copymethod:: Collection *linrand
68 copymethod:: Collection *exprand
70 copymethod:: Collection *fib
78 copymethod:: ArrayedCollection -at
80 copymethod:: ArrayedCollection -put
82 copymethod:: ArrayedCollection -insert
84 copymethod:: ArrayedCollection -overWrite
86 copymethod:: ArrayedCollection -clipAt
88 copymethod:: ArrayedCollection -wrapAt
90 copymethod:: ArrayedCollection -foldAt
92 copymethod:: ArrayedCollection -slice
94 copymethod:: ArrayedCollection -clipPut
96 copymethod:: ArrayedCollection -wrapPut
98 copymethod:: ArrayedCollection -foldPut
100 copymethod:: ArrayedCollection -swap
102 copymethod:: ArrayedCollection -replace
104 copymethod:: ArrayedCollection -++
106 copymethod:: ArrayedCollection -add
108 copymethod:: ArrayedCollection -addAll
110 copymethod:: ArrayedCollection -addFirst
112 copymethod:: ArrayedCollection -removeAt
114 copymethod:: ArrayedCollection -collect
116 copymethod:: ArrayedCollection -do
118 copymethod:: ArrayedCollection -reverseDo
120 copymethod:: ArrayedCollection -deepCollect
122 copymethod:: ArrayedCollection -reshape
124 copymethod:: ArrayedCollection -bubble
126 copymethod:: ArrayedCollection -unbubble
128 copymethod:: ArrayedCollection -windex
130 copymethod:: ArrayedCollection -size
132 copymethod:: ArrayedCollection -normalize
134 copymethod:: ArrayedCollection -normalizeSum
136 copymethod:: ArrayedCollection -plot
139 Returns a new Array whose elements are reversed. The receiver is unchanged.
148 Returns a new Array whose elements have been scrambled. The receiver is unchanged.
150 [1, 2, 3, 4, 5, 6].scramble.postln;
154 Return a new Array which is the receiver made into a palindrome.
155 The receiver is unchanged.
157 [1, 2, 3, 4].mirror.postln;
161 Return a new Array which is the receiver made into a palindrome with the last element removed.
162 This is useful if the list will be repeated cyclically, the first element will not get played twice.
163 The receiver is unchanged.
165 [1, 2, 3, 4].mirror1.postln;
169 Return a new Array which is the receiver concatenated with a reversal of itself.
170 The center element is duplicated. The receiver is unchanged.
172 [1, 2, 3, 4].mirror2.postln;
176 Return a new Array whose elements are repeated n times. The receiver is unchanged.
178 [1, 2, 3].stutter(2).postln;
184 Return a new Array whose elements are in rotated order. The receiver is unchanged.
186 [1, 2, 3, 4, 5].rotate(1).postln;
187 [1, 2, 3, 4, 5].rotate(-1).postln;
188 [1, 2, 3, 4, 5].rotate(3).postln;
191 Number of elements to rotate. Negative n values rotate left, postive n values
195 Return a new Array whose elements have been reordered via one of 10 "counting" algorithms.
196 Run the examples to see the algorithms.
199 [1, 2, 3, 4].pyramid(i + 1).postcs;
202 argument::patternType
203 Choose counting algorithm. The algorithms are numbered 1 through 10.
206 Like pyramid, but keep the resulting values grouped in subarrays.
209 [1, 2, 3, 4].pyramid(1).postln;
210 [1, 2, 3, 4].pyramidg(1).postln;
214 Return a new Array of length maxlen with the items partly repeated (random choice of given probability).
217 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].sputter(0.5, 16).postln;
218 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].sputter(0.8, 8).postln;
220 argument::probability
221 Probability of repeat.
223 The length of the new Array.
226 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.
228 x = [ [1, 2, 3], 6, List["foo", 'bar']];
235 Returns a new Array whose elements are the nthPermutation of the elements of the receiver. The receiver is unchanged.
238 6.do({|i| x.permute(i).postln;});
242 Returns a new Array whose elements contain all possible combinations of the receiver's subcollections.
244 [[1, 2, 3, 4, 5], [10, 20, 30]].allTuples;
245 [[1, 2, 3, 4, 5], [10, 20, 30], [5, 6]].allTuples;
249 Returns a new Array whose elements are repeated sequences of the receiver, up to size length. The receiver is unchanged.
251 x = [ 1, 2, 3, "foo", 'bar' ];
258 Same as wrapExtend but the sequences fold back on the list elements.
267 Same as wrapExtend but the sequences "clip" (return their last element) rather than wrapping.
276 Return a new Array whose elements are repeated subsequences from the receiver.
277 Easier to demonstrate than explain.
279 [1, 2, 3, 4, 5, 6].slide(3, 1).postcs;
280 [1, 2, 3, 4, 5, 6].slide(3, 2).postcs;
281 [1, 2, 3, 4, 5, 6].slide(4, 1).postcs;
285 Shift the values of the array n steps to the right (n positive) or to the left(n negative),
286 dropping the excess and filling empty space with zero.
288 [1, 2, 3, 4, 5, 6].shift(3).postln;
289 [1, 2, 3, 4, 5, 6].shift(-3).postln;
292 method::containsSeqColl
293 Returns true if the receiver Array contains any instance of SequenceableCollection
295 [1, 2, 3, 4].containsSeqColl.postln
296 [1, 2, [3], 4].containsSeqColl.postln
300 Returns all possible combinations of the array's elements.
302 [1, 2, 3].powerset.postln
303 [1, 2, 3].powerset.sort({ |a, b| a.size > b.size }); // sort by size, big first
304 [1, 2, 3].powerset.sort({ |a, b| a.size > b.size }).reverse; // by size, small first
306 powerset is also supported in Collection:
308 Set[1, 2, 3].powerset;
309 List[1, 2, 3].powerset
310 (a: 1, b: 2, c: 3).powerset;
314 Given an array of symbols, this returns an array of pairs of (symbol, value) from the current environment.
315 This can then be used as arguments for a Synth, or in an OSC message.
317 e = (freq: 340, amp: 0.001, strangeness: 0.85);
319 [\amp, \taste, \strangeness].envirPairs;
324 Invert rows and colums in a two dimensional Array (turn inside out).
325 See also: Function, SequenceableCollection.
327 [[1, 2, 3], [4, 5, 6]].flop;
328 [[1, 2, 3], [4, 5, 6], [7, 8]].flop; // shorter array wraps
329 [].flop; // result is always 2-d.
332 method::multiChannelExpand
333 Used by UGens to perform multi channel expansion. Same as flop.
336 Some UGens return Arrays of OutputProxy when instantiated. This method allows you to
337 get at the source UGen.
345 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.
347 // an array of routine functions:
350 { 1.wait; \done_one.postln },
351 { 0.5.wait; \done_two.postln },
352 { 0.2.wait; \done_three.postln }
359 a.fork(0); \doneAll.postln;
366 a.fork(1); \doneAll.postln;
372 "join = a.size (default).".postcln;
373 a.fork; \doneAll.postln;
377 poll(trig, label, trigid)
378 apply an array of Poll units to an array of UGens (see those helpfiles for more details).
383 SinOsc.ar([0.1, 0.2], 0).poll * 0.1
386 x.trace; // By tracing the Synth you can see the two Poll units we created
391 apply an array of Dpoll units to an array of UGens (see those helpfiles for more details).
393 method::atIdentityHash
394 This method is used by IdentitySet to search for a key among its members.
396 method::atIdentityHashInPairs
397 This method is used by IdentityDictionary to search for a key among its members.
400 Returns a string representing the Array. May not be compileable due to ellision (...) of excessive arguments.
402 method::asCompileString
403 Returns a string that will compile to return an Array equal to the receiver.
405 method::isValidUGenInput
406 Returns true. Arrays are valid UGen inputs.
409 Returns the OSC measse as an Int8Array. Receiver must be a bundle.
411 [0.1, [\s_new, \default, -1, 1, 1, \freq, 1961]].asRawOSC;