Variable Argument Functions

To declare a function taking a variable number of arguments, use the following:

HOW DUZ I <functionname> YR <variable-name> [ AN  YR <variable-name> ...] AN ALL YR <multi-variable-argument-name>

closed with a

OIC

The <multi-variable-argument-name> identifier may be used in the function to access the arguments. The identifier refers to a bukkit. The arguments to the function are placed in slots on the bukkit. The slot identifier is the index of the argument (index starting at 0).

The ALL YR <multi-variable-argument-name> identifier can only be the last parameter in a function definition.

Examples

BTW This function adds all variables passed in.
HOW DUZ I ated ALL YR BASE
    I HAS A zigs ITZ 0
    I HAS A greatjustice ITZ 0

    BTW Loop over all variables and add them
    IM IN YR Bases UPPIN YR zigs WILE BASE!!!zigs
       greatjustice R SUM OF greatjustice AN BASE!!!zigs
    IM OUTTA YR Bases
    
    
    FOUND YR greatjustice 
OIC

Calling:

I HAS A hamburger ITZ 7
I HAS A cheezburger ITZ 5
I HAS A fry ITZ 3

ated hamburger cheezburger fry    BTW  15

Variable Argument Calling

The companion to vararg functions is vararg calling:

SUM OF ALL BASE

(Note: this assumes that SUM is infinite-arity rather than binary, but then again it probably should be…)

proposals/1.3/vararg.txt · Last modified: 2007/07/22 19:48 by sabik
Recent changes RSS feed Creative Commons License Donate Driven by DokuWiki