2 summary::list of items of variable size
4 categories::Collections>Ordered
7 List is a subclass of SequenceableCollection with unlimited growth in size. Although not a subclass of link::Classes/Array:: or its superclass link::Classes/ArrayedCollection:: it uses an Array in its implementation and is in many cases interchangeable with one. (List implements many of the same methods as Array.)
9 Arrays have a fixed maximum size. If you add beyond that size a new Array is created and returned, but you must use an assignment statement or the new array will be lost. (See the link::Classes/Array:: helpfile.) List has no size limitation and is thus more flexible, but has slightly more overhead.
14 5.do({ arg i; z = x.add(i); y.add(i); });
15 x.postln; z.postln; y.postln;
19 Many of List's methods are inherited from link::Classes/SequenceableCollection:: or link::Classes/Collection:: and are documented in those helpfiles.
24 Creates a List with the initial capacity given by strong::size::.
27 Creates a List with the initial capacity given by strong::size:: and slots filled with nil.
30 Creates a List by copying strong::aList::'s array variable.
33 Creates a List using strong::anArray::.
38 Returns a new link::Classes/Array:: based upon this List.
41 Returns the List's Array, allowing it to be manipulated directly. This should only be necessary for exotic manipulations not implemented in List or its superclasses.
51 Sets the List's Array.
54 Return the item at strong::index::.
56 List[ 1, 2, 3 ].at(0).postln;
60 Same as link::#-at::, but values for strong::index:: greater than the size of the List will be clipped to the last index.
67 Same as link::#-at::, but values for strong::index:: greater than the size of the List will be wrapped around to 0.
70 y.wrapAt(3).postln; // this returns the value at index 0
71 y.wrapAt(4).postln; // this returns the value at index 1
75 Same as link::#-at::, but values for strong::index:: greater than the size of the List will be folded back.
78 y.foldAt(3).postln; // this returns the value at index 1
79 y.foldAt(4).postln; // this returns the value at index 0
80 y.foldAt(5).postln; // this returns the value at index 1
84 Put strong::item:: at strong::index::, replacing what is there.
87 Same as link::#-put::, but values for strong::index:: greater than the size of the List will be clipped to the last index.
90 Same as link::#-put::, but values for strong::index:: greater than the size of the List will be wrapped around to 0.
93 Same as link::#-put::, but values for strong::index:: greater than the size of the List will be folded back.
96 Adds an strong::item:: to the end of the List.
99 Inserts the strong::item:: at the beginning of the List.
102 Inserts the strong::item:: into the contents of the List at the indicated strong::index::.
105 Remove and return the last element of the List.
108 Increase the size of the List by strong::sizeIncrease:: number of slots.
111 Remove and return the element at strong::index::, shrinking the size of the List.
119 Inserts the item into the contents of the receiver, possibly returning a new collection. note::the difference between this and link::Classes/Collection#fill#Collection's *fill::.::
123 z = List[1, 2, 3, 4];
125 z.fill([1,2,3,4]).postln;
130 Iterate over the elements in order, calling the function for each element. The function is passed two arguments, the element and an index.
132 List['a', 'b', 'c'].do({ arg item, i; [i, item].postln; });
136 Iterate over the elements in reverse order, calling the function for each element. The function is passed two arguments, the element and an index.
138 List['a', 'b', 'c'].reverseDo({ arg item, i; [i, item].postln; });
142 Calls function for each subsequent pair of elements in the List. The function is passed the two elements and an index.
144 List[1, 2, 3, 4, 5, 6].pairsDo({ arg a, b; [a, b].postln; });
148 Return a new List which is a copy of the indexed slots of the receiver from start to end.
152 z = List[1, 2, 3, 4, 5];
153 y = z.copyRange(1,3);
160 Return a new List consisting of the values starting at strong::first::, then every step of the distance between strong::first:: and strong::second::, up until strong::last::.
164 z = List[1, 2, 3, 4, 5, 6];
165 y = z.copySeries(0, 2, 5);
171 Put strong::value:: at every index starting at strong::first::, then every step of the distance between strong::first:: and strong::second::, up until strong::last::.
175 z = List[1, 2, 3, 4, 5, 6];
176 y = z.putSeries(0, 2, 5, "foo");
182 Return a new List whose elements are reversed.
186 z = List[1, 2, 3, 4];
194 Returns a new List whose elements have been scrambled. The receiver is unchanged.
196 List[1, 2, 3, 4, 5, 6].scramble.postln;
200 Return a new List which is the receiver made into a palindrome. The receiver is unchanged.
202 List[1, 2, 3, 4].mirror.postln;
206 Return a new List which is the receiver made into a palindrome with the last element removed. This is useful if the list will be repeated cyclically, the first element will not get played twice. The receiver is unchanged.
208 List[1, 2, 3, 4].mirror1.postln;
212 Return a new List which is the receiver concatenated with a reversal of itself. The center element is duplicated. The receiver is unchanged.
214 List[1, 2, 3, 4].mirror2.postln;
218 Return a new List whose elements are repeated strong::n:: times. The receiver is unchanged.
220 List[1, 2, 3].stutter(2).postln;
224 Return a new List whose elements are in rotated order. Negative strong::n:: values rotate left, postive strong::n:: values rotate right. The receiver is unchanged.
226 List[1, 2, 3, 4, 5].rotate(1).postln;
227 List[1, 2, 3, 4, 5].rotate(-1).postln;
228 List[1, 2, 3, 4, 5].rotate(3).postln;
232 Return a new List whose elements have been reordered via one of 10 "counting" algorithms. The algorithms are numbered 1 through 10. Run the examples to see the algorithms.
234 List[1, 2, 3, 4].pyramid(1).postln;
238 List[1, 2, 3, 4].pyramid(i + 1).postcs;
244 Returns a new List whose elements are interlaced sequences of the elements of the receiver's subcollections, up to size strong::length::. The receiver is unchanged.
247 x = List[ [1, 2, 3], 6, List["foo", 'bar']];
255 Returns a new List whose elements are the strong::nthPermutation:: of the elements of the receiver. The receiver is unchanged.
259 6.do({|i| x.permute(i).postln;});
264 Returns a new List whose elements are repeated sequences of the receiver, up to size strong::length::. The receiver is unchanged.
267 x = List[ 1, 2, 3, "foo", 'bar' ];
275 Same as link::#-lace:: but the sequences fold back on the list elements.
278 x = List[ 1, 2, "foo"];
286 Return a new List whose elements are repeated subsequences from the receiver. Easier to demonstrate than explain.
288 List[1, 2, 3, 4, 5, 6].slide(3, 1).postcs;
289 List[1, 2, 3, 4, 5, 6].slide(3, 2).postcs;
290 List[1, 2, 3, 4, 5, 6].slide(4, 1).postcs;
294 Dump the List's Array.
297 Replace the List's Array with a new empty one.