Previous: , Up: Miscellaneous Utilities   [Index]


13.16.2 Function Creators

apply

object apply(object o, ...);

is a new function, calling o with the unnamed arguments of ‘apply’ followed by its own.

The applied arguments are checked for number and type against the o function definition. Reference variadic arguments for o are applied value only.

A max with 8 function creation example:

    integer (*f)(integer);

    f = max.apply(8);

apply_i

object apply_i(object o, ...);

is a new function, calling o with every second optional argument of ‘apply_i’ in the position indicated by the preceding optional argument, and its own arguments filling in and trailing the sparse sequence of applied arguments.

The applied arguments are checked for number and type against the o function definition.

Only the last application for a given position is observed, with the rest being ignored.

Maximum 127 arguments may be applied. No variadic arguments may be applied.

A base 12 file integer writer creation example:

    file (*f)(file, integer);

    f = f_xinteger.apply_i(1, 12);

apply_j

object apply_j(object o, ...);

is a new function, calling o with arguments of ‘apply_j’, and with its own arguments filling in and trailing the sparse sequence of applied arguments. Application starts in order from o, with sequences of arguments to apply introduced by their count, and zero indicating a skipped (i.e. not applied) o argument.

The applied arguments are checked for number and type against the o function definition. Reference variadic arguments for o are applied value only.

apply_j’ allows no more than 256 arguments of its own.

To apply x, y and z for the 3rd, 4th and 6th arguments of a function fa:

    apply_j(fa, 0, 0, 2, x, y, 0, 1, z);

cons

object cons(object o, integer p, object q);

is a new function, calling o with its own arguments, minus a range starting at p that is replaced with the evaluation result of function q called over the substituted range.

The list of parameter types of the new function matches the combined lists of o and q.

If q is variadic and it substitutes the last non variadic argument of o or a variadic one, the variadic arguments of the new function go to q. Otherwise, if o is variadic, the variadic arguments go to o.

Constructing a function from one taking three arguments and one taking two, with the second substituting the middle argument of the first:

    f = o.cons(1, q);
    f(a, b, c, d);

The second call is equivalent to:

    o(a, q(b, c), d);

Parameter Application

No reference parameters can be applied, except for intrinsic numerical.

See Calling Functions.

See Variadic Functions.


Previous: Function Callers, Up: Miscellaneous Utilities   [Index]