GETARGV

Purpose:

Returns a variable argument from an SPL routine.

Syntax:

GETARGV(n)

n

-

An integer, the index of the variable argument.

Returns:

The value of the variable input argument.

Example:

/* maximum of one or more inputs */
vmax(argv)
{
    local i, s;
 
    /* 0 or 1 arg case */
    if (argc < 2)
    {
        if (argc < 1)
        {
            s = maxval();
        }
        else
        {
            s = maxval(getargv(1));
        }
    }
    else
    {
        /* initialize */
        s = maxval(getargv(1), getargv(2));
 
        /* compare input args */
        loop (i = 3..argc)
        {
            s = maxval(s, getargv(i));
        }
    }
    
    return(s);
}

 

 

vmax(2, 3, 1, 5, 4)

 

returns 5, the maximum of the input arguments.

 

ARGV in the argument list of an SPL routine specifies a variable number of input arguments. The above routine returns the maximum of two or more expressions.

 

ARGC returns the total number of input arguments and GETARGV obtains a particular variable argument.

Remarks:

The input for GETARGV specifies the index of the variable argument so getargv(2) refers to the second variable argument. Consider:

 

fact2(a, b, argv)
{
    local f, i;
 
    if (argc < 2)
    {
        error("fact - at least two inputs required");
    }
 
    f = a * b;
 
    loop (i = 1..argc - 2)
    {
        f *= getargv(i);
    }
 
    return(f);
}

 

fact2(2, 3, 4, 5, 6, 7) == 5040

 

FACT2 is an SPL routine that accepts 2 specified arguments and any number of variable arguments. The result is the product of all the arguments. The expression getargv(i) returns the ith variable argument.

See Also:

ARGCOUNT

ARGV

ISVARIABLE

OUTARGC