# function

    .function name:{String} body:{Lambda} -> Void

Content copied to clipboard

Defines a custom function that can be called later in the document.

The function is saved in the current context, and can be shared via mechanisms such as include or subdocuments.

    .function {myfunction}
        You have called this function!

Content copied to clipboard

The function can be called normally:

    .myfunction

Content copied to clipboard

The amount of parameters is determined by the amount of explicit lambda parameters.

    .function {add}
        a b:
        This function has two parameters, `a` and `b`.

Content copied to clipboard

Arguments can be accessed as in a function call by name:

    .function {greet}
        from to:
        **Hello .to** from .from

Content copied to clipboard

When calling the function, argoments can be positional, named, or a mix of both:

    .greet {John} {world}

Content copied to clipboard

    .greet from:{John} to:{world}

Content copied to clipboard

A parameter might also be optional. In this case, if the corresponding argument is not provided, it will be `none`:

    .function {greet}
       from to?:
       **Hello .to** from .from

Content copied to clipboard

As with any none value, operations defined in the `Optionality` stdlib module help dealing with it, including simulating default values:

    .function {greet}
       from to?:
       **Hello .to::otherwise {world}** from .from

Content copied to clipboard

#### Parameters

name

name of the function

body

- Likely a body argument

content of the function. Function parameters must be explicit lambda parameters

#### Throws

IllegalStateException

if a function with the same name already exists and function overwriting is forbidden by the current options

#### Wiki page

declaring-functions