Partial Substitution

If we have a function
f = (x, y) -> exp(-(x^2 + y^2)) * sqrt(x^2 + y^2);
we don't have to pass the values of both arguments to f all at the same time. Instead, we may pass the value of y to f, and leave x unspecified. The result is a new function of x. An unspecified argument value is represented by a dot.
f1 = f(., 3)
Here the definition of function f1 is

We call such a function call a partial substitution.

In general, when calling a function, some input arguments can receive dots as values, while the rest receive actual values. The result of such a function call is a new function whose input arguments are those given dots, while the arguments of the original function which do get values passed to are no longer arguments of the new function. Here a dot means a missing or delayed value, and corresponds to an argument of the new function. Calling the new function is equivalent to calling the original function by two separate steps of argument passing. For example:

>> f = function (x, y, alpha) -> s
           s = (x^alpha + y^alpha) ^ (1 / alpha);
    end

>> f2 = f(., ., 2);
>> f2(3, 4)    // equivalent to f(3, 4, 2)
   5
A function call in which all argument values are dots will have no effect - it just evaluates to the original function. For example, sin(.) is the same as sin.

With the support of partial substitution, we can write a general function, which takes many arguments. Then for a particular application, all calls to the master function may use the same values for some arguments. Then we may create a customized version of the function by partially substituting these often used argument values into the function. The calling sequence of the customized function is more compact. For example, a plotting function may be designed to take all the following arguments

plot = function (x, y, coord, line_style, color,
                            axis, xlabel, ylabel) -> graph
                 .....
                 .....
       end
If every time we use the same choice of coordinates, line style, color setting, axis, xlabel, and ylabel, then we can do
myplot = plot(., ., "cartesian", "solid", "bw", "boxed",
                                  "population", "revenue");
to make a plotting function that takes only x and y as arguments.

Partial substitution provides an alternative way to function parameters for customizing the behavior of a function after it is created. Unlike parameterized functions in which some variable are predefined to be parameters, in partial substitutions any of the input variables can be chosen as parameters. However, in terms of performance it may be at disadvantage compared to the function parameter approach since one more abstract level is added and two argument passing steps have to be processed in order to perform a call to a partial substitution.

oz 2009-12-22