A.1.8 Calling Octave Functions from Oct-Files

There is often a need to be able to call another Octave function from
within an oct-file, and there are many examples of such within Octave
itself. For example, the quad function is an oct-file that
calculates the definite integral by quadrature over a user supplied
function.

There are also many ways in which a function might be passed. It might
be passed as one of

Function Handle

Anonymous Function Handle

Inline Function

String

The example below demonstrates an example that accepts all four means of
passing a function to an oct-file.

When the user function is passed as a string the treatment of the
function is different. In some cases it is necessary to have the
user supplied function as an octave_function object. In that
case the string argument can be used to create a temporary function
as demonstrated below.

There are two important things to know in this case. First, the number of
input arguments to the user function is fixed, and in the above example is
a single argument. Second, to avoid leaving the temporary function in the
Octave symbol table it should be cleared after use. Also, by convention
internal function names begin and end with the character sequence ‘__’.