Search code examples
emacselisp

Put list as arguments to elisp function


Ok, let's suppose we have a function like format in elisp:

(format "%s, %s" "Hello" "World!")  ;; returns "Hello, World!"

How can I get the same results if I have arguments as a list? In other words how to fix next form?

(equal "Hello, World!" (format "%s, %s" (list "Hello" "World")))

Solution

  • Use apply:

    (apply 'format "%s, %s" (list "Hello" "World"))
    

    apply accepts a function name (quoted), and then any number of "normal" arguments, and the final argument should be a list, that's appended after the "normal" arguments.