What is the argument count limit to a function call?

I think that max-specpdl-size is related to answer:

This variable defines the limit on the total number of local variable bindings and ‘unwind-protect’ cleanups that are allowed before Emacs signals an error

but I don't think that defun makes local binding using let.

I try (macroexpand-all '(defun my (x) (+ x 1))) C-u C-x e and get:

(defalias (quote my) (function (lambda (x) (+ x 1))))

So I check eval.c for evaluator code:

apply_lambda (Lisp_Object fun, Lisp_Object args, ptrdiff_t count) {
  EMACS_INT numargs;
  register Lisp_Object *arg_vector;

  numargs = XFASTINT (Flength (args));
  SAFE_ALLOCA_LISP (arg_vector, numargs);

which leads to SAFE_ALLOCA_LISP:

#define SAFE_ALLOCA_LISP(buf, nelt)                            \
  do {                                                         \
    if ((nelt) <= lisp_word_count (sa_avail))                  \
      (buf) = AVAIL_ALLOCA ((nelt) * word_size);               \
    else if ((nelt) <= min (PTRDIFF_MAX, SIZE_MAX) / word_size) \
      {                                                        \
        Lisp_Object arg_;                                      \
        (buf) = xmalloc ((nelt) * word_size);                  \
        arg_ = make_save_memory (buf, nelt);                   \
        sa_must_free = true;                                   \
        record_unwind_protect (free_save_value, arg_);         \
      }                                                        \
    else                                                       \
      memory_full (SIZE_MAX);                                  \
  } while (false)

That piece is hard for me to understand… Rest of the code doesn't seem to expose any restriction but I am unsure…

Compare with Common Lisp constants: LAMBDA-PARAMETERS-LIMIT and CALL-ARGUMENTS-LIMIT.

  • Just out of curiosity, what's the use case? Why do you want to know the limit (if there is a definite one) - what will you use it for?
    – Drew
    Sep 21, 2015 at 1:24

1 Answer 1


I believe this is limited only by amount of available memory. I couldn't find any information about this sort of limitation in official manual, so it generally means that number of arguments an Emacs Lisp function can take is not limited on language level, otherwise it would be explicitly mentioned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.