Partial Application

Partial application fixes part or all of the parameters of a function to generate a new function with fewer parameters.




To fix the first few parameters, we do not need to indicate the remaining parameters; if there are any free parameters before a fixed parameter, the positions of these free parameters must be indicated. Please refer to the examples below.

Partial application can be used with template functions that have certain requirements about function inputs.


$ a=100
$ g=add{a*a};
$ g(8);

$ add{a*a}(88);

$ def f(a,b):a*exp(b)
$ g=f{10};  // g(b)==f(10,b)

$ g(0);

$ g(1);

$ k=f{,1};  // k(a)==f(a,1)
$ k(10);

If there is a free optional parameter before a fixed parameter, and its position is not indicated, it must be specified when the partially applied function is called.

//Calculate the singular value decomposition of matrix m.
//The syntax of function svd is svd(obj, [fullMatrices=true], [computeUV=true]). Since f1 does not have the optional *fullMatrices* parameter fixed, you must specify *fullMatrices* when executing f1, otherwise an error will be reported.
f1 = svd{m, computeUV=true}
f1(false)   //Successfully executed.
f1()  //An error is reported: The function [svd] expects 1 argument(s), but the actual number of arguments is: 0