1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
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: 9.0px Monaco
; min-height: 12.0px}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #bf0000}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #000000; min-height: 12.0px}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #000000}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #606060}
17 span
.s1
{font: 18.0px Helvetica
}
18 span
.s2
{color: #0024f8}
19 span
.s3
{color: #0000bf}
20 span
.s4
{color: #606060}
21 span
.s5
{color: #000000}
22 span
.Apple-tab-span
{white-space:pre
}
26 <p class=
"p1"><span class=
"s1"><b>FunctionList
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b></span><b>multiple function
</b></p>
27 <p class=
"p2"><br></p>
28 <p class=
"p1"><b>superclass: AbstractFunction
</b></p>
29 <p class=
"p3"><br></p>
30 <p class=
"p3"><br></p>
31 <p class=
"p1">A
<b>FunctionList
</b> is a function that composes multiple functions into one. This allows allow to deal transparently with several functions as if they were one and to append new functions at a later point. The functions are evaluated in the order they have in the FunctionList's array, which is by default the order in which they have been added to it.
</p>
32 <p class=
"p2"><br></p>
33 <p class=
"p1">See the
<a href=
"../../Language/Functions.html"><span class=
"s2">Functions
</span></a> help file for a basic introduction.
</p>
34 <p class=
"p2"><br></p>
35 <p class=
"p1"><b>*new(functions)
</b><span class=
"Apple-converted-space"> </span></p>
36 <p class=
"p1"><span class=
"Apple-tab-span"> </span>create a new instance.
<i>functions
</i> is an array of functions or objects
</p>
37 <p class=
"p2"><br></p>
38 <p class=
"p1"><b>array
</b><span class=
"Apple-tab-span"> </span>return the FunctionList's array. New functions can be added to the array dierctly, e.g.
</p>
39 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>x = FunctionList(...some functions);
<span class=
"Apple-converted-space"> </span>x.array = x.array.insert(
2, aFunction);
</p>
40 <p class=
"p2"><br></p>
41 <p class=
"p1"><b>array_(array)
</b><span class=
"Apple-tab-span"> </span>set the array of the FunctionList.
</p>
42 <p class=
"p2"><br></p>
43 <p class=
"p2"><br></p>
44 <p class=
"p1"><b>addFunc(function, function ..)
</b><span class=
"Apple-converted-space"> </span></p>
45 <p class=
"p1"><span class=
"Apple-tab-span"> </span>This message is used to be able to add to
<b>an Object
</b>, to a
<b>Function
</b>, or to a
<b>FunctionList
</b>.
</p>
46 <p class=
"p1"><span class=
"Apple-tab-span"> </span>nil.addFunc returns a function, if only one function is passed in the argument.
</p>
47 <p class=
"p1"><span class=
"Apple-tab-span"> </span>function.addFunc then returns a FunctionList.
<span class=
"Apple-converted-space"> </span></p>
48 <p class=
"p2"><br></p>
49 <p class=
"p1"><b>removeFunc(function)
</b>, remove a function from the list.
<span class=
"Apple-converted-space"> </span></p>
50 <p class=
"p1"><span class=
"Apple-tab-span"> </span>returns
<b>the last function
</b> when only one function is left.
</p>
51 <p class=
"p1"><span class=
"Apple-tab-span"> </span>returns
<b>nil
</b> when the last function was removed.
</p>
52 <p class=
"p2"><br></p>
53 <p class=
"p1">addFunc and removeFunc are implemented for
<b>Nil
</b>,
<b>Object
</b> and
<b>FunctionList
</b></p>
54 <p class=
"p2"><br></p>
55 <p class=
"p1"><span class=
"Apple-tab-span"> </span>nil.addFunc(f):
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>returns f
</p>
56 <p class=
"p1"><span class=
"Apple-tab-span"> </span>obj.addFunc(f):
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>returns FunctionList([obj, f])
</p>
57 <p class=
"p2"><br></p>
58 <p class=
"p1"><span class=
"Apple-tab-span"> </span>nil.removeFunc(f)
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>returns nil
</p>
59 <p class=
"p1"><span class=
"Apple-tab-span"> </span>obj.removeFunc(f)
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>returns nil, if f === obj, else obj is returned
</p>
60 <p class=
"p2"><br></p>
61 <p class=
"p3"><br></p>
62 <p class=
"p3"><br></p>
63 <p class=
"p4">// example
</p>
64 <p class=
"p5"><br></p>
65 <p class=
"p6">a =
<span class=
"s3">nil
</span>;
</p>
66 <p class=
"p6">a = a.addFunc {
<span class=
"s3">|
x=
"",
y=
""|
</span> <span class=
"s4">"this % is an % example\n"</span>.postf(x, y);
1 };
</p>
67 <p class=
"p6">a.postln;
</p>
68 <p class=
"p6">a = a.addFunc {
<span class=
"s3">|
x=
"",
y=
""|
</span> <span class=
"s4">"there is no % that is %\n"</span>.postf(x, y);
2 };
</p>
69 <p class=
"p6">a.value;
</p>
70 <p class=
"p7"><span class=
"s5">a.value(
</span>"text"<span class=
"s5">,
</span>"extraordinary well written"<span class=
"s5">)
</span></p>
71 <p class=
"p6">a.valueArray([
<span class=
"s4">"x"</span>,
<span class=
"s4">"y"</span>]);
</p>
72 <p class=
"p5"><br></p>
73 <p class=
"p4">// Function:do vs FunctionList:do (same)
</p>
74 <p class=
"p6">a.do {
<span class=
"s3">|x|
</span> x.value };
</p>
75 <p class=
"p6">{
4 }.do {
<span class=
"s3">|x|
</span> x.value.postln }
</p>
76 <p class=
"p5"><br></p>
78 <p class=
"p6">().use {
</p>
79 <p class=
"p6"><span class=
"Apple-tab-span"> </span>~x =
<span class=
"s4">"array"</span>;
</p>
80 <p class=
"p7"><span class=
"s5"><span class=
"Apple-tab-span"> </span>~y =
</span>"ominous"<span class=
"s5">;
</span></p>
81 <p class=
"p6"><span class=
"Apple-tab-span"> </span>a.valueEnvir;
</p>
82 <p class=
"p6"><span class=
"Apple-tab-span"> </span>a.valueEnvir(
<span class=
"s4">"list"</span>);
</p>
85 <p class=
"p5"><br></p>
86 <p class=
"p5"><br></p>
87 <p class=
"p4">// removing a function
</p>
88 <p class=
"p6">x = {
<span class=
"s4">"removal test"</span>.postln };
</p>
89 <p class=
"p6">a.addFunc(x);
</p>
90 <p class=
"p6">a.value;
</p>
91 <p class=
"p6">a = a.removeFunc(x);
</p>
92 <p class=
"p6">a.value;
</p>
93 <p class=
"p5"><br></p>
94 <p class=
"p4">// mathematics
</p>
95 <p class=
"p6">a =
<span class=
"s3">nil
</span>;
</p>
96 <p class=
"p6">a = a.addFunc({
1.0.rand }).addFunc({ [
0,
1].choose });
</p>
97 <p class=
"p6">a = a.squared.linexp(
0,
1,
1.0,
500);
</p>
98 <p class=
"p5"><br></p>
99 <p class=
"p6">a.value;
</p>
100 <p class=
"p5"><br></p>
101 <p class=
"p5"><br></p>
102 <p class=
"p4">// compatibility with function multichannel expansion
</p>
103 <p class=
"p6">a =
<span class=
"s3">nil
</span>;
</p>
104 <p class=
"p6">a = a.addFunc {
<span class=
"s3">|x=
0|
</span> if(x
> 0) {
7 } {
1000.rand } };
</p>
105 <p class=
"p6">a = a.addFunc {
<span class=
"s3">|x=
0|
</span> if(x
< 0) {
17 } { -
1000.rand } };
</p>
106 <p class=
"p6">a.value
</p>
107 <p class=
"p5"><br></p>
108 <p class=
"p6">a = a.flop;
</p>
109 <p class=
"p6">a.value
</p>
110 <p class=
"p6">a.value([-
1,
1])
</p>
111 <p class=
"p5"><br></p>
112 <p class=
"p5"><br></p>
113 <p class=
"p5"><br></p>
114 <p class=
"p4">// typical usage in a Document action
</p>
115 <p class=
"p4">// see also SCView: addAction example.
</p>
116 <p class=
"p5"><br></p>
117 <p class=
"p6">d =
<span class=
"s3">Document
</span>.current;
</p>
118 <p class=
"p6">d.keyDownAction = {
<span class=
"s4">"You touched the keyboard."</span>.postln };
</p>
119 <p class=
"p5"><br></p>
120 <p class=
"p6">d.keyDownAction = d.keyDownAction.addFunc {:x, x
<-(
1..), ::
<span class=
"s4">"already % times\n\n"</span>.postf(x) };
</p>
121 <p class=
"p5"><br></p>
122 <p class=
"p5"><br></p>
123 <p class=
"p6">d.keyDownAction =
<span class=
"s3">nil
</span>;
</p>
124 <p class=
"p5"><br></p>
125 <p class=
"p4">// even if you don't know if there is already an action defined
</p>
126 <p class=
"p4">// one can add one.
</p>
127 <p class=
"p5"><br></p>
129 <p class=
"p6">d.keyDownAction =
<span class=
"s3">nil
</span>;
</p>
130 <p class=
"p6">d.keyDownAction = d.keyDownAction.addFunc {:x, x
<-(
1..), ::
<span class=
"s4">"already % times\n\n"</span>.postf(x) };
</p>
131 <p class=
"p5"><br></p>
133 <p class=
"p5"><br></p>
134 <p class=
"p6">d.keyDownAction =
<span class=
"s3">nil
</span>;
</p>
135 <p class=
"p5"><br></p>
136 <p class=
"p5"><br></p>
137 <p class=
"p5"><br></p>
138 <p class=
"p5"><br></p>