/usr/share/SuperCollider/HelpSource/Reference/Partial-Application.schelp is in supercollider-common 1:3.8.0~repack-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | title:: Partial Application
summary:: Create Functions via Partial Application
categories:: Language
related:: Reference/Functions
Partial application is a way to create a function by passing only some arguments to a method. The code::_:: character stands in for missing arguments and becomes an argument to the created function.
It only applies to a single method, list, or dictionary call, not to a more complex nested expression.
for example:
code::
f = _ + 2;
::
f is now a function of one argument.
code::
f.value(7); // returns 9
::
it is equivalent to having written:
code::
f = {|x| x + 2 };
::
(except that there is no name 'x' declared)
code::
g = Point(_, _);
::
g is a function of two arguments.
code::
g.value(3, 4);
::
Here are some example usages of this in a collect message. Below each is written the equivalent function.
code::
(1..8).collect(_.isPrime);
(1..8).collect {|x| x.isPrime };
(1..8).collect(_.hash);
(1..8).collect {|x| x.hash };
(1..8).collect([\a, \b, _]);
(1..8).collect {|x| [\a, \b, x] };
(1..8).collect((a:_));
(1..8).collect {|x| (a:x) };
(1..8).collect(Polar(_, pi));
(1..8).collect {|x| Polar(x, pi) };
(1..8).collect((1.._));
(1..8).collect {|x| (1..x) };
::
code::
f = (a:_, b:_); // f is a two argument function
g = f.(_, 5); // g is a partial application of f
g.(7); // get the answer
// equivalent to this:
f = {|x, y| (a:x, b:y) }
g = {|z| f.(z, 5) };
g.value(7);
::
An example of what you can't do:
code::
(1..8).collect( Point(100 * _, 50) ); // nested expression won't work.
// only the * gets partially applied, not the surrounding expression.
(1..8).collect {|x| Point(100 * x, 50) }; // need to use a function for this.
::
|