1 class::AbstractFunction
2 summary::An object which responds to a set of messages that represent mathematical functions
3 categories::Core>Kernel
4 related::Classes/UGen,Classes/Pattern,Classes/Function,Overviews/Operators
8 An AbstractFunction is an object which responds to a set of messages that represent
9 mathematical functions. Subclasses override a smaller set of messages to respond
10 to the mathematical functions. The intent is to provide a mechanism for functions
11 that do not calculate values directly but instead compose structures for calculating.
13 Function, Pattern, Stream and UGen are subclasses of AbstractFunction.
14 For example, if you multiply two UGens together the receiver responds by answering a new
15 instance of class BinaryOpUGen which has the two operands as inputs.
17 For an overview of common operators, see link::Overviews/Operators::.
18 To see which classes implements a specific method, see that method in the generated link::Overviews/Methods:: overview.
22 subsection::Unary Messages
24 All of the following messages send the message composeUnaryOp to the receiver with the
25 unary message selector as an argument.
26 See link::Classes/UnaryOpFunction::.
74 method::isStrictlyPositive
78 subsection::Binary Messages
80 All of the following messages send the message composeBinaryOp to the receiver with the
81 binary message selector and the second operand as arguments.
82 See: link::Classes/BinaryOpFunction::.
128 method::bitHammingDistance
131 subsection:: Messages with more arguments
133 All of the following messages send the message code::composeNAryOp:: to the receiver with the
134 binary message selector and the other operands as arguments.
135 See link::Classes/NAryOpFunction::.
150 Interface that allows us to combine selectors (Symbols) and Functions. Sends valueArray(args) to this.
155 f = [{ |a, b| a * b * 100.rand }, { |a, b| sin(a) * sin(b) }, '*', '/'];
156 f.choose.postcs.applyTo(3, 4);
158 // this is used in SequenceableCollection reduce:
160 (1..10).reduce({ |a, b| a * b * 1.0.rand });
165 returns:: the result of sending the value(for) message to this.
171 f = { SinOsc.ar(400) };
172 g = { LFPulse.kr(8) };
173 product = f * g * 0.1;
174 { Pan2.ar(product, SinOsc.kr(0.3)) }.play;
183 f = { |x| sin(3*x)*cos(8*x) }
184 f.plotGraph2(from:0,to:2);
185 f.sampled(10,0,2).plotGraph2(from:0,to:2);
186 f.sampled(80,0,2).plotGraph2(from:0,to:2);
188 //on complicated functions a sampled function is less cpy heavy.
189 f = { |x| 60.collect{ 2**((x-rrand(0.0,1.0))) }.sum/60 };
190 f.plotGraph2(from:0,to:1);
192 g.plotGraph2(from:0,to:1);
193 { 200.collect{ f.(rand(0.0,1.0)) } }.bench;
194 { 200.collect{ g.(rand(0.0,1.0)) } }.bench;
197 subsection::Function Composition
199 When unary, binary or n-ary operators are applied to an abstract function, it returns an object that represents
200 this operation, without evaluating the function: link::Classes/UnaryOpFunction::, link::Classes/BinaryOpFunction::, link::Classes/NAryOpFunction::.
201 Note that different subclasses like link::Classes/Pattern:: or link::Classes/UGen:: have their own composition scheme analogous to the one of AbstractFunction itself. For more about functions, see link::Classes/Function::.
208 a = { 1.0.rand } + 8;
212 y = { 8 } + { 1.0.rand };
217 // arguments are passed into both functions
219 y = { |x=0| x } + { 1.0.rand };
223 y = { |x=0| x * 3 } + { |x=0| x + 1.0.rand };
228 y = { |x=0| x * 3 } + { |x=0| x + 1.0.rand } * { |x=0| [50, 100].choose + x } + 1.0;
233 // environments can be used as a lookup with valueEnvir:
239 ~z = { |x=8| x } + { |y=0| y + 1.0.rand };
248 a = blend({ 3.0.rand }, { 1000.rand }, { |frac| frac });
251 a.value((0, 0.06..1)); // creates a range of values..