Variadic Function

In computer programming, a variadic function is a function of indefinite arity, i.e., one which accepts a variable number of arguments. Support for variadic functions differs widely among programming languages.

There are many mathematical and logical operations that come across naturally as variadic functions. For instance, the summing of numbers or the concatenation of strings or other sequences are operations that can logically apply to any number of operands.

Another operation that has been implemented as a variadic function in many languages is output formatting. The C function printf and the Common Lisp function format are two such examples. Both take one argument that specifies the formatting of the output, and any number of arguments that provide the values to be formatted.

Variadic functions can expose type-safety problems in some languages. For instance, C's printf, if used incautiously, can give rise to a class of security holes known as format string attacks. The attack is possible because the language support for variadic functions is not type-safe; it permits the function to attempt to pop more arguments off the stack than were placed thereā€”corrupting the stack and leading to unexpected behavior.

Variadic functionality can be considered complementary to the apply function, which takes a function and a list/sequence/array as arguments, 'applies' the function to each element in the sequence, and returns the list of return values (which will be of the same length as the original array).

Read more about Variadic Function:  Specific Implementations

Famous quotes containing the word function:

    We are thus able to distinguish thinking as the function which is to a large extent linguistic.
    Benjamin Lee Whorf (1897–1934)