# Why is there a limit on the number of function arguments?

I am reading `:help :call`, which states the following:

Call a function. The name of the function and its arguments are as specified with `:function`. Up to 20 arguments can be used.

This makes me wondering: why is there a seemingly artificial limit on the number of function arguments?

-
This place is not official by any means. Did you consider asking on the vim_dev mailing list and/or reading the source? – romainl Mar 28 at 9:57
... the latter being of, of course, the answer: "Because that's how it was made" :D – VanLaser Mar 28 at 10:30
One can also argue that, if more than N arguments are needed, using a list or dictionary function argument instead would be clearly the alternative (more organized) solution. "20" is the "enforce" limit of this solution :) – VanLaser Mar 28 at 11:18
I hereby declare that 4 should be the absolute maximum number of arguments. – romainl Mar 28 at 12:09
"First shalt thou take out the Holy Function, then shalt thou count arguments to three, no more, no less. Three shall be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, neither count thou two, excepting that thou then proceed to three. Five is right out. Once the number three, being the third number, be reached, then callest thou thy Holy Function of Antioch towards thy foe, who being naughty in My sight, shall return it." – muru Mar 28 at 16:14

Because this is the size of the data structures used to store function arguments. From `eval.c`:

``````#define MAX_FUNC_ARGS   20      /* maximum number of function arguments */

/* structure to hold info for a function that is currently being executed. */
typedef struct funccall_S funccall_T;

struct funccall_S
{
[..]
listitem_T  l_listitems[MAX_FUNC_ARGS];     /* listitems for a:000 */
[..]
};

[..]

/*
* Allocate a variable for the result of a function.
* Return OK or FAIL.
*/
static int
get_func_tv(
)
{
typval_T    argvars[MAX_FUNC_ARGS + 1];     /* vars for arguments */

[..]

/*
* Get the arguments.
*/
argp = *arg;
while (argcount < MAX_FUNC_ARGS - (partial == NULL ? 0 : partial->pt_argc))
{
[..]
}
}
``````

Well, and so forth.

Could this be made dynamic to allow an arbitrary amount of arguments? Sure. But why?

``````fun! TooManyForSanity(one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty, twentyone)
echo "Well..."
endfun

call TooManyForSanity('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'OH MY GOD IT NEVER ENDS')
``````

This is the sort of code that makes programmers go mad and murder innocent bunnies in their sleep.

-
I think that the important question is: is it the mad programmers, or the bunnies, who are in their sleep at the time of execution? – L Spice Mar 28 at 22:50
Bunnies! Bunnies! It must be BUNNIES! (BTW, the way to properly execute bunnies: `:command! Bunnies echo "Squeeeak!"`; `:execute "Bunnies"`) – Amadan Mar 29 at 4:20