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::.
129 method::bitHammingDistance
132 subsection:: Messages with more arguments
134 All of the following messages send the message code::composeNAryOp:: to the receiver with the
135 binary message selector and the other operands as arguments.
136 See link::Classes/NAryOpFunction::.
151 Interface that allows us to combine selectors (Symbols) and Functions. Sends valueArray(args) to this.
156 f = [{ |a, b| a * b * 100.rand }, { |a, b| sin(a) * sin(b) }, '*', '/'];
157 f.choose.postcs.applyTo(3, 4);
159 // this is used in SequenceableCollection reduce:
161 (1..10).reduce({ |a, b| a * b * 1.0.rand });
166 returns:: the result of sending the value(for) message to this.
172 f = { SinOsc.ar(400) };
173 g = { LFPulse.kr(8) };
174 product = f * g * 0.1;
175 { Pan2.ar(product, SinOsc.kr(0.3)) }.play;
184 f = { |x| sin(3*x)*cos(8*x) }
185 f.plotGraph2(from:0,to:2);
186 f.sampled(10,0,2).plotGraph2(from:0,to:2);
187 f.sampled(80,0,2).plotGraph2(from:0,to:2);
189 //on complicated functions a sampled function is less cpy heavy.
190 f = { |x| 60.collect{ 2**((x-rrand(0.0,1.0))) }.sum/60 };
191 f.plotGraph2(from:0,to:1);
193 g.plotGraph2(from:0,to:1);
194 { 200.collect{ f.(rand(0.0,1.0)) } }.bench;
195 { 200.collect{ g.(rand(0.0,1.0)) } }.bench;
198 subsection::Function Composition
200 When unary, binary or n-ary operators are applied to an abstract function, it returns an object that represents
201 this operation, without evaluating the function: link::Classes/UnaryOpFunction::, link::Classes/BinaryOpFunction::, link::Classes/NAryOpFunction::.
202 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::.
209 a = { 1.0.rand } + 8;
213 y = { 8 } + { 1.0.rand };
218 // arguments are passed into both functions
220 y = { |x=0| x } + { 1.0.rand };
224 y = { |x=0| x * 3 } + { |x=0| x + 1.0.rand };
229 y = { |x=0| x * 3 } + { |x=0| x + 1.0.rand } * { |x=0| [50, 100].choose + x } + 1.0;
234 // environments can be used as a lookup with valueEnvir:
240 ~z = { |x=8| x } + { |y=0| y + 1.0.rand };
249 a = blend({ 3.0.rand }, { 1000.rand }, { |frac| frac });
252 a.value((0, 0.06..1)); // creates a range of values..