Next: , Previous: , Up: Functions   [Index]


9.3 Calling Functions

Functions are called with arguments in the number and types prescribed by the function parameters lists.

Implicit convertions are performed between related types for function arguments, notably between intrinsic numerical types and between the ‘object’ type and any other type.

The types of the argument values must either match or be convertible to the function described parameter types.

See The Object Type.

See The Intrinsic Types.

See Implicit Convertions.

Function calls evaluate to values of the declared type.

The primary function call syntax has the function name followed by the parantheses enclosed list of arguments, with the arguments comma separated.

    abs(-3);
    pow(4, 4);
    o_integer(0);
    o_real(4, sin(.5));
    r_put(r, "key", "data");
    o_newline();

A secondary function call syntax has the first argument before the function name, with a period sign (‘.’) between the two.

Certain prefixes may be stripped from the function names, provided that the leading function argument matches exactly for type.

    4.pow(4);
    l.length();
    "syntax".length();
    r.put("key", "data");

The prefix stripped name is a calling convenience and its usefulness goes only so far. It does not by itself identify the function (in the above examples, ‘length’ refers to two functions, the ‘length’ and ‘l_length’ ones).

The prefix stripped name must be a valid identifier (it may not start with a digit).

If both a prefixed and an unprexifed name functions exist, the prefixed one is chosen.

void l_ff(list);
void ff(list);

    list().ff();

In this, the called function is ‘l_ff’.

For the reversed secondary call syntax, the parentheses may be omitted for functions taking only one argument:

    375.bcount;
    "syntax".length + "777".atoi;

Reference function parameters ask for read/write variable arguments. The exceptions are variadic parameters and, in most contexts, intrinsic numerical parameters.

See Variadic Functions.


Next: Substituting Evaluation Result, Previous: Function Declarations, Up: Functions   [Index]