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


8.2 Positional Arguments Access

Function argument values may be accessed by their position in the input set via function and operator interfaces.

count

integer count(void);

Is the number of (aime) function arguments.

integer
three(integer a, real b, text c)
{
    return count();
}

The function ‘three’ returns 3.

lead

object lead(integer p);

Is the argument in the p position.

integer
first(integer a, real b, text c)
{
    return lead(0);
}

The function ‘first’ returns the value of a.

set

void set(integer p, object o);

Sets the argument in the p position as o.

integer
six(integer a, real b, text c)
{
    set(0, 1);
    set(1, 2r);
    set(2, "3");

    return a + b + atoi(c);
}

The function ‘six’ returns 6.

$

object $integer

The operator ‘$’ is the argument in the p position, same as ‘lead’.

integer
last(integer a, real b, text c)
{
    return $2;
}

The function ‘last’ returns the value of c.

Display the parameter types, one per line, starting with the first:

    integer i;

    i = -count();
    while (i) {
	o_plan(__type($i), "\n");
	i += 1;
    }

xcall

object xcall(object o, &...);

Is the return of the function indicated by o called with all the remaining arguments of xcall and all the arguments of the aime function featuring the call.

The variadic arguments are passed by reference where possible.

void
fx1(integer a)
{
    xcall(o_bfxinteger, 8, 32, 2);
}

The function ‘fx1’ prints a in base 2 with 32 digits grouped in comma separated blocks of 8 digits.

rcall

object rcall(object o, integer p, integer f, integer l, &...);

Is the return of the function indicated by o called with the unnamed arguments of rcall and the f to l arguments of the aime function featuring the call at the position p in the list of unnamed arguments of rcall.

The variadic arguments are passed by reference where possible.

If l indicates an element prior to f the arguments starting with the f indexed one to the end of the list and those from the beginning of the list to the l indexed one are used (as if the list of arguments was circular).

void
fx2(integer a, integer b, integer c, integer d)
{
    rcall(o_form, 1, 1, 2, "~ ~\n");
    rcall(o_form, 1, 3, 0, "~ ~\n");
}

The function ‘fx2’ prints b and c on the first line and d and a on the second.

lcall

object lcall(object o, integer r, &...);

Is the return of the function indicated by o called with ranges of arguments of the aime function featuring the call and the arguments of the call following range indications. r is the number of subsequent range indications, each expected a triplet of intrinsic integers: an insertion position and the indeces of the first and last arguments to be copied.

The aime function argument ranges are inserted in the list of used lcall arguments (i.e. the arguments following the range indications) and insertion positions are interpreted with respect to the latter. If more ranges are to be inserted at the same position, they are inserted in the order in which they appear.

If the last argument index in a range specification indicates an element prior to the first argument index, the arguments starting with the one indexed first to the end of the list and those from the beginning of the list to the one indexed last are used (as if the list of arguments was circular).

Negative insertion positions and argument indeces are interpreted with respect to the end of the relevant list.

void
fx3(integer a, integer b, integer c, integer d, integer e, integer f,
    integer g, integer h, integer i)
{
    lcall(o_plan, 4, 0, 0, 1, 2, 3, 5, 4, 6, 8, 0, 2, 2, "a", "b", "c", "d");
}

The function ‘fx3’ prints the sequence a, b, c, d, with the first three argument preceding the first letter, the middle three arguments in between the second and the third letter and the last three arguments following the last letter.


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