cmake build system: visiblity support for clang
[supercollider.git] / Help / Collections / List.html
blob11e20863143e5351542b1dd36a7cc5041d9450a8
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="949.43">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #0021e7}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica}
15 p.p6 {margin: 0.0px 0.0px 0.0px 42.0px; font: 12.0px Helvetica}
16 p.p7 {margin: 0.0px 0.0px 0.0px 42.0px; font: 12.0px Helvetica; min-height: 14.0px}
17 p.p8 {margin: 0.0px 0.0px 0.0px 42.0px; font: 9.0px Monaco}
18 p.p9 {margin: 0.0px 0.0px 0.0px 42.0px; font: 9.0px Monaco; color: #ad140d}
19 p.p10 {margin: 0.0px 0.0px 0.0px 42.0px; font: 12.0px Monaco; min-height: 16.0px}
20 p.p11 {margin: 0.0px 0.0px 0.0px 42.0px; font: 10.0px Monaco; min-height: 14.0px}
21 p.p12 {margin: 0.0px 0.0px 0.0px 42.0px; font: 9.0px Monaco; min-height: 12.0px}
22 p.p13 {margin: 0.0px 0.0px 0.0px 42.0px; font: 12.0px Helvetica; color: #001bb9; min-height: 14.0px}
23 span.s1 {font: 18.0px Helvetica}
24 span.s2 {color: #000000}
25 span.s3 {color: #001bb9}
26 span.s4 {color: #606060}
27 span.s5 {color: #2c7014}
28 span.Apple-tab-span {white-space:pre}
29 </style>
30 </head>
31 <body>
32 <p class="p1"><span class="s1"><b>List<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></span><b>list of items of variable size</b></p>
33 <p class="p2"><br></p>
34 <p class="p3"><span class="s2"><b>Inherits from: </b><a href="../Core/Object.html"><b>Object</b></a><b> : </b><a href="Collection.html"><b>Collection</b></a></span><span class="s3"><b> :</b></span><span class="s2"><b> </b><a href="SequenceableCollection.html"><b>SequenceableCollection</b></a></span></p>
35 <p class="p2"><br></p>
36 <p class="p1">List is a subclass of SequenceableCollection with unlimited growth in size. Although not a subclass of <a href="Array.html"><span class="s3">Array</span></a> or its superclass <a href="ArrayedCollection.html"><span class="s3">ArrayedCollection</span></a> it uses an Array in its implementation and is in many cases interchangeable with one. (List implements many of the same methods as Array.)</p>
37 <p class="p2"><br></p>
38 <p class="p1">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 <b>Array </b>helpfile.) List has no size limitation and is thus more flexible, but has slightly more overhead.</p>
39 <p class="p2"><br></p>
40 <p class="p4">(</p>
41 <p class="p4">x = <span class="s3">Array</span>.new(3);<span class="Apple-converted-space"> </span></p>
42 <p class="p4">y = <span class="s3">List</span>.new(3);<span class="Apple-converted-space"> </span></p>
43 <p class="p4">5.do({ <span class="s3">arg</span> i; z = x.add(i); y.add(i); });<span class="Apple-converted-space"> </span></p>
44 <p class="p4">x.postln; z.postln; y.postln;</p>
45 <p class="p4">)</p>
46 <p class="p2"><br></p>
47 <p class="p1">Many of List's methods are inherited from <a href="SequenceableCollection.html"><span class="s3"><b>SequenceableCollection</b></span></a><b> </b>or <a href="Collection.html"><span class="s3"><b>Collection</b></span></a><b> </b>and are documented in those helpfiles.</p>
48 <p class="p2"><br></p>
49 <p class="p2"><br></p>
50 <p class="p5"><b>Class Methods</b></p>
51 <p class="p2"><br></p>
52 <p class="p1"><b>*new(size)</b></p>
53 <p class="p6">Creates a List with the initial capacity given by <b>size</b>.</p>
54 <p class="p7"><br></p>
55 <p class="p1"><b>*newClear(size)</b></p>
56 <p class="p6">Creates a List with the initial capacity given by <b>size</b> and slots filled with nil.</p>
57 <p class="p7"><br></p>
58 <p class="p1"><b>*copyInstance(aList)</b></p>
59 <p class="p6">Creates a List by copying <b>aList's</b> array variable.</p>
60 <p class="p7"><br></p>
61 <p class="p1"><b>*newUsing(anArray)</b></p>
62 <p class="p6">Creates a List using <b>anArray</b>.</p>
63 <p class="p7"><br></p>
64 <p class="p7"><br></p>
65 <p class="p7"><br></p>
66 <p class="p5"><b>Instance Methods</b></p>
67 <p class="p2"><br></p>
68 <p class="p1"><b>asArray</b></p>
69 <p class="p6">Returns a new <b>Array</b> based upon this List.</p>
70 <p class="p7"><br></p>
71 <p class="p1"><b>array</b></p>
72 <p class="p6">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.</p>
73 <p class="p7"><br></p>
74 <p class="p8">(</p>
75 <p class="p8">x = <span class="s3">List</span>[1, 2, 3];</p>
76 <p class="p8">x.array.add(<span class="s4">"foo"</span>);</p>
77 <p class="p8">x.postln;</p>
78 <p class="p8">)</p>
79 <p class="p7"><br></p>
80 <p class="p1"><b>array_(anArray)</b></p>
81 <p class="p6">Sets the List's Array.</p>
82 <p class="p7"><br></p>
83 <p class="p1"><b>at(index)</b></p>
84 <p class="p6">Return the <b>item</b> at <b>index</b>.</p>
85 <p class="p7"><br></p>
86 <p class="p8"><span class="s3">List</span>[ 1, 2, 3 ].at(0).postln;</p>
87 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
88 <p class="p1"><b>clipAt(index)</b></p>
89 <p class="p6">Same as <b>at</b>, but values for <b>index</b> greater than the size of the List will be clipped to the last index.</p>
90 <p class="p7"><br></p>
91 <p class="p8">y = <span class="s3">List</span>[ 1, 2, 3 ];</p>
92 <p class="p8">y.clipAt(13).postln;</p>
93 <p class="p7"><span class="Apple-converted-space"> </span></p>
94 <p class="p1"><b>wrapAt(index)</b></p>
95 <p class="p6">Same as <b>at</b>, but values for <b>index</b> greater than the size of the List will be wrapped around to 0.</p>
96 <p class="p7"><br></p>
97 <p class="p8">y = <span class="s3">List</span>[ 1, 2, 3 ];</p>
98 <p class="p9"><span class="s2">y.wrapAt(3).postln; </span>// this returns the value at index 0</p>
99 <p class="p9"><span class="s2">y.wrapAt(4).postln; </span>// this returns the value at index 1</p>
100 <p class="p7"><br></p>
101 <p class="p1"><b>foldAt(index)</b></p>
102 <p class="p6">Same as <b>at</b>, but values for <b>index</b> greater than the size of the List will be folded back.</p>
103 <p class="p7"><br></p>
104 <p class="p8">y = <span class="s3">List</span>[ 1, 2, 3 ];</p>
105 <p class="p9"><span class="s2">y.foldAt(3).postln; </span>// this returns the value at index 1</p>
106 <p class="p9"><span class="s2">y.foldAt(4).postln; </span>// this returns the value at index 0</p>
107 <p class="p9"><span class="s2">y.foldAt(5).postln; </span>// this returns the value at index 1</p>
108 <p class="p7"><br></p>
109 <p class="p1"><b>put(index, item)</b></p>
110 <p class="p6">Put <b>item</b> at <b>index</b>, replacing what is there.</p>
111 <p class="p7"><br></p>
112 <p class="p1"><b>clipPut(index, item)</b></p>
113 <p class="p6">Same as <b>put</b>, but values for <b>index</b> greater than the size of the List will be clipped to the last index.</p>
114 <p class="p7"><span class="Apple-converted-space"> </span></p>
115 <p class="p1"><b>wrapPut(index, item)</b></p>
116 <p class="p6">Same as <b>put</b>, but values for <b>index</b> greater than the size of the List will be wrapped around to 0.</p>
117 <p class="p7"><br></p>
118 <p class="p1"><b>foldPut(index)</b></p>
119 <p class="p6">Same as <b>put</b>, but values for <b>index</b> greater than the size of the List will be folded back.</p>
120 <p class="p7"><br></p>
121 <p class="p1"><b>add(item)</b></p>
122 <p class="p6">Adds an <b>item</b> to the end of the List.</p>
123 <p class="p7"><br></p>
124 <p class="p1"><b>addFirst(item)</b></p>
125 <p class="p6">Inserts the <b>item</b> at the beginning of the List.</p>
126 <p class="p10"><br></p>
127 <p class="p1"><b>insert(index, item)</b></p>
128 <p class="p6">Inserts the <b>item</b> into the contents of the List at the indicated <b>index</b>.</p>
129 <p class="p10"><br></p>
130 <p class="p1"><b>pop</b></p>
131 <p class="p6">Remove and return the last element of the List.</p>
132 <p class="p7"><br></p>
133 <p class="p1"><b>grow(sizeIncrease)</b></p>
134 <p class="p6">Increase the size of the List by <b>sizeIncrease </b>number of slots.</p>
135 <p class="p7"><br></p>
136 <p class="p1"><b>removeAt(index)</b></p>
137 <p class="p6">Remove and return the element at <b>index</b>, shrinking the size of the List.</p>
138 <p class="p7"><br></p>
139 <p class="p8">y = <span class="s3">List</span>[ 1, 2, 3 ];<span class="Apple-converted-space"> </span></p>
140 <p class="p8">y.removeAt(1);<span class="Apple-converted-space"> </span></p>
141 <p class="p8">y.postln;</p>
142 <p class="p7"><br></p>
143 <p class="p1"><b>fill(value)</b></p>
144 <p class="p6">Inserts the item into the contents of the receiver, possibly returning a new collection. Note the difference between this and Collection's *fill.</p>
145 <p class="p7"><br></p>
146 <p class="p8">(</p>
147 <p class="p8"><span class="s3">var</span> z;</p>
148 <p class="p8">z = <span class="s3">List</span>[1, 2, 3, 4];</p>
149 <p class="p8">z.fill(4).postln;</p>
150 <p class="p8">z.fill([1,2,3,4]).postln;</p>
151 <p class="p8">)</p>
152 <p class="p11"><br></p>
153 <p class="p1"><b>do(function)</b></p>
154 <p class="p6">Iterate over the elements in order, calling the function for each element. The function is passed two arguments, the element and an index.</p>
155 <p class="p7"><br></p>
156 <p class="p8"><span class="s3">List</span>[<span class="s5">'a'</span>, <span class="s5">'b'</span>, <span class="s5">'c'</span>].do({ <span class="s3">arg</span> item, i; [i, item].postln; });</p>
157 <p class="p12"><br></p>
158 <p class="p1"><b>reverseDo(function)</b></p>
159 <p class="p6">Iterate over the elements in reverse order, calling the function for each element. The function is passed two arguments, the element and an index.</p>
160 <p class="p7"><br></p>
161 <p class="p8"><span class="s3">List</span>[<span class="s5">'a'</span>, <span class="s5">'b'</span>, <span class="s5">'c'</span>].reverseDo({ <span class="s3">arg</span> item, i; [i, item].postln; });</p>
162 <p class="p12"><br></p>
163 <p class="p1"><b>pairsDo(function)</b></p>
164 <p class="p6">Calls function for each subsequent pair of elements in the SequentialCollection.</p>
165 <p class="p6">The function is passed the two elements and an index.</p>
166 <p class="p7"><br></p>
167 <p class="p8"><span class="s3">List</span>[1, 2, 3, 4, 5, 6].pairsDo({ <span class="s3">arg</span> a, b; [a, b].postln; });</p>
168 <p class="p7"><br></p>
169 <p class="p1"><b>copyRange(start, end)</b></p>
170 <p class="p6">Return a new List which is a copy of the indexed slots of the receiver from start to end.</p>
171 <p class="p10"><br></p>
172 <p class="p8">(</p>
173 <p class="p8"><span class="s3">var</span> y, z;</p>
174 <p class="p8">z = <span class="s3">List</span>[1, 2, 3, 4, 5];</p>
175 <p class="p8">y = z.copyRange(1,3);</p>
176 <p class="p8">z.postln;</p>
177 <p class="p8">y.postln;</p>
178 <p class="p8">)</p>
179 <p class="p12"><br></p>
180 <p class="p1"><b>copySeries(first, second, last)</b></p>
181 <p class="p6">Return a new List consisting of the values starting at <b>first</b>, then every step of the distance between <b>first</b> and <b>second</b>, up until <b>last</b>.</p>
182 <p class="p10"><br></p>
183 <p class="p8">(</p>
184 <p class="p8"><span class="s3">var</span> y, z;</p>
185 <p class="p8">z = <span class="s3">List</span>[1, 2, 3, 4, 5, 6];</p>
186 <p class="p8">y = z.copySeries(0, 2, 5);</p>
187 <p class="p8">y.postln;</p>
188 <p class="p8">)</p>
189 <p class="p12"><br></p>
190 <p class="p1"><b>putSeries(first, second, last, value)</b></p>
191 <p class="p6">Put <b>value</b> at every index starting at <b>first</b>, then every step of the distance between <b>first</b> and <b>second</b>, up until <b>last</b>.</p>
192 <p class="p10"><br></p>
193 <p class="p8">(</p>
194 <p class="p8"><span class="s3">var</span> y, z;</p>
195 <p class="p8">z = <span class="s3">List</span>[1, 2, 3, 4, 5, 6];</p>
196 <p class="p8">y = z.putSeries(0, 2, 5, <span class="s4">"foo"</span>);</p>
197 <p class="p8">y.postln;</p>
198 <p class="p8">)</p>
199 <p class="p12"><br></p>
200 <p class="p1"><b>reverse</b></p>
201 <p class="p6">Return a new List whose elements are reversed.</p>
202 <p class="p7"><br></p>
203 <p class="p8">(</p>
204 <p class="p8"><span class="s3">var</span> y, z;</p>
205 <p class="p8">z = <span class="s3">List</span>[1, 2, 3, 4];</p>
206 <p class="p8">y = z.reverse;</p>
207 <p class="p8">z.postln;</p>
208 <p class="p8">y.postln;</p>
209 <p class="p8">)</p>
210 <p class="p12"><br></p>
211 <p class="p1"><b>scramble</b></p>
212 <p class="p6">Returns a new List whose elements have been scrambled. The receiver is unchanged.</p>
213 <p class="p13"><br></p>
214 <p class="p8"><span class="s3">List</span>[1, 2, 3, 4, 5, 6].scramble.postln;</p>
215 <p class="p10"><br></p>
216 <p class="p1"><b>mirror</b></p>
217 <p class="p6">Return a new List which is the receiver made into a palindrome.<span class="Apple-converted-space"> </span></p>
218 <p class="p6">The receiver is unchanged.</p>
219 <p class="p7"><br></p>
220 <p class="p8"><span class="s3">List</span>[1, 2, 3, 4].mirror.postln;</p>
221 <p class="p7"><br></p>
222 <p class="p1"><b>mirror1</b></p>
223 <p class="p6">Return a new List which is the receiver made into a palindrome with the last element removed.<span class="Apple-converted-space"> </span></p>
224 <p class="p6">This is useful if the list will be repeated cyclically, the first element will not get played twice.</p>
225 <p class="p6">The receiver is unchanged.</p>
226 <p class="p7"><br></p>
227 <p class="p8"><span class="s3">Lis</span>t[1, 2, 3, 4].mirror1.postln;</p>
228 <p class="p7"><br></p>
229 <p class="p1"><b>mirror2</b></p>
230 <p class="p6">Return a new List which is the receiver concatenated with a reversal of itself. The center element is duplicated. The receiver is unchanged.</p>
231 <p class="p7"><br></p>
232 <p class="p8"><span class="s3">Lis</span>t[1, 2, 3, 4].mirror2.postln;</p>
233 <p class="p7"><br></p>
234 <p class="p1"><b>stutter(n)</b></p>
235 <p class="p6">Return a new List whose elements are repeated n times. The receiver is unchanged.</p>
236 <p class="p7"><br></p>
237 <p class="p8"><span class="s3">Lis</span>t[1, 2, 3].stutter(2).postln;</p>
238 <p class="p7"><br></p>
239 <p class="p1"><b>rotate(n)</b></p>
240 <p class="p6">Return a new List whose elements are in rotated order. Negative n values rotate left, postive n values rotate right. The receiver is unchanged.</p>
241 <p class="p7"><br></p>
242 <p class="p8"><span class="s3">Lis</span>t[1, 2, 3, 4, 5].rotate(1).postln;</p>
243 <p class="p12"><br></p>
244 <p class="p8"><span class="s3">Lis</span>t[1, 2, 3, 4, 5].rotate(-1).postln;</p>
245 <p class="p12"><br></p>
246 <p class="p8"><span class="s3">Lis</span>t[1, 2, 3, 4, 5].rotate(3).postln;</p>
247 <p class="p7"><br></p>
248 <p class="p1"><b>pyramid</b></p>
249 <p class="p6">Return a new List whose elements have been reordered via one of 10 "counting" algorithms.</p>
250 <p class="p6">The algorithms are numbered 1 through 10. Run the examples to see the algorithms.</p>
251 <p class="p7"><br></p>
252 <p class="p8"><span class="s3">Lis</span>t[1, 2, 3, 4].pyramid(1).postln;</p>
253 <p class="p10"><br></p>
254 <p class="p8">(</p>
255 <p class="p8">10.do({ <span class="s3">arg</span> i;</p>
256 <p class="p8"><span class="Apple-tab-span"> </span><span class="s3">Lis</span>t[1, 2, 3, 4].pyramid(i + 1).postcs;</p>
257 <p class="p8">});</p>
258 <p class="p8">)</p>
259 <p class="p2"><br></p>
260 <p class="p1"><b>lace(length)</b></p>
261 <p class="p6">Returns a new List whose elements are interlaced sequences of the elements of the receiver's subcollections, up to size <b>length</b>. The receiver is unchanged.</p>
262 <p class="p7"><br></p>
263 <p class="p8">(</p>
264 <p class="p8">x = <span class="s3">List</span>[ [1, 2, 3], 6, <span class="s3">List</span>[<span class="s4">"foo"</span>, <span class="s5">'bar'</span>]];</p>
265 <p class="p8">y = x.lace(12);</p>
266 <p class="p8">x.postln;</p>
267 <p class="p8">y.postln;</p>
268 <p class="p8">)</p>
269 <p class="p7"><br></p>
270 <p class="p1"><b>permute(nthPermutation)</b></p>
271 <p class="p6">Returns a new List whose elements are the <b>nthPermutation</b> of the elements of the receiver. The receiver is unchanged.</p>
272 <p class="p7"><br></p>
273 <p class="p8">(</p>
274 <p class="p8">x = <span class="s3">List</span>[ 1, 2, 3];</p>
275 <p class="p8">6.do({|i| x.permute(i).postln;});</p>
276 <p class="p8">)</p>
277 <p class="p7"><br></p>
278 <p class="p1"><b>wrapExtend(length)</b></p>
279 <p class="p6">Returns a new List whose elements are repeated sequences of the receiver, up to size <b>length</b>. The receiver is unchanged.</p>
280 <p class="p7"><br></p>
281 <p class="p8">(</p>
282 <p class="p8">x = <span class="s3">List</span>[ 1, 2, 3, <span class="s4">"foo"</span>, <span class="s5">'bar'</span> ];</p>
283 <p class="p8">y = x.wrapExtend(9);</p>
284 <p class="p8">x.postln;</p>
285 <p class="p8">y.postln;</p>
286 <p class="p8">)</p>
287 <p class="p7"><br></p>
288 <p class="p1"><b>foldExtend(length)</b></p>
289 <p class="p6">Same as <b>lace</b> but the sequences fold back on the list elements.</p>
290 <p class="p12"><br></p>
291 <p class="p8">(</p>
292 <p class="p8">x = <span class="s3">List</span>[ 1, 2, <span class="s4">"foo"</span>];</p>
293 <p class="p8">y = x.foldExtend(9);</p>
294 <p class="p8">x.postln;</p>
295 <p class="p8">y.postln;</p>
296 <p class="p8">)</p>
297 <p class="p7"><br></p>
298 <p class="p1"><b>slide(windowLength, stepSize)</b></p>
299 <p class="p6">Return a new List whose elements are repeated subsequences from the receiver.<span class="Apple-converted-space"> </span></p>
300 <p class="p6">Easier to demonstrate than explain.</p>
301 <p class="p7"><br></p>
302 <p class="p8"><span class="s3">Lis</span>t[1, 2, 3, 4, 5, 6].slide(3, 1).postcs;</p>
303 <p class="p12"><br></p>
304 <p class="p8"><span class="s3">Lis</span>t[1, 2, 3, 4, 5, 6].slide(3, 2).postcs;</p>
305 <p class="p12"><br></p>
306 <p class="p8"><span class="s3">Lis</span>t[1, 2, 3, 4, 5, 6].slide(4, 1).postcs;</p>
307 <p class="p12"><br></p>
308 <p class="p1"><b>dump</b></p>
309 <p class="p6">Dump the List's Array.</p>
310 <p class="p7"><br></p>
311 <p class="p1"><b>clear</b></p>
312 <p class="p6">Replace the List's Array with a new empty one.</p>
313 </body>
314 </html>