<sect1><title>Nickle Functions</title>
<para>
An example function might be declared like this:
<informalexample><screen><![CDATA[
int gcf ( int a, int b ) {
        int f = 1;
        for ( int i = 2; i <= abs ( a ) && i <= abs ( b ); ++i )
                while ( ( a // f ) % i == 0 && ( b // f ) % i == 0 )
                        f *= i;
        return f;
}
]]></screen></informalexample>
</para>
<para>
First comes the return type of the function, then the function name, then the list of arguments (with types), and finally the statement list in curly braces.
If any types are left off, Nickle assumes <literal>poly</literal>.
In any case, all typechecking is done at runtime.
</para>
<para>
A function can take any number of arguments.
The final argument may be succeeded by an ellipses (...) to indicate an arbitrary, variable number of succeeding arguments, each of the type of the final argument; the last argument takes on a list value to store them.
<informalexample><screen>
...
> print sum
int sum (int a, int b ...)
{
    for (int i = 0; i < dim (b); ++i)
        a += b[i];
    return a;
}
> sum(1,2)
3
> sum(4)
4
> sum(1,2,4,6)
13
</screen></informalexample>
</para>
<para>
Functions are called as in C, with their names followed by argument values in parentheses:
<informalexample><screen>
foo ( "hello", 7.2 );
</screen></informalexample>
</para>
<para>
Since they are first class, functions can be assigned:
<informalexample><screen>
int(int,int) a = gcf;
</screen></informalexample>
</para>
<para>
See the section on Copy semantics for details on what functions may be assigned to each other.
</para>
<para>
Functions may also be declared and used anonymously:
<informalexample><screen>
(int func ( int a, int b ) { return a + b; })(2,3);     /* 5 */
</screen></informalexample>
</para>
<para>
Replacing the function name with the keyword <literal>func</literal> indicates its anonymity.
</para>
</sect1>
