0

Here is a simple example in which I would like to replace

(start-process "ls" "*temp*" "ls" "-l" "-a" "-t" "-r") ; this works

with

(setq some-var ????) ; <-- Need to figure this part out
(start-process "ls" "*temp*" "ls" some-var)

But I cannot figure out how to represent that some-var.

Below did not work:

;; Attempt 1
(setq some-var "-l -a -t -r")

;; Attempt 2
(setq some-var '("-l" "-a" "-t" "-r"))

I basically need a solution to be able to provide variable number of args (&rest args) to a function using a variable.

1

1 Answer 1

4

You are looking for the function apply. Use it as follows:

(setq some-var '("-l" "-a" "-t" "-r"))
(apply #'start-process "ls" "*temp*" "ls" some-var)
2
  • @PythonNut You don't need function as long as the byte-compiler does not complain. start-process is used as symbol here. There is nothing the byte-compiler can optimize. Otherwise function would also be used there: gnu.org/software/emacs/manual/html_node/elisp/…. function is useful for lambda-expressions and other evaluable lisp expressions.
    – Tobias
    Commented Feb 18, 2016 at 8:09
  • 2
    @Tobias I tend to think of the sharp quote as being an annotation for the reader as well, just so it's extra clear that start-process is intended to be interpreted as a function. With that in mind, I tend to sharp-quote all symbols referencing functions for consistency.
    – PythonNut
    Commented Feb 18, 2016 at 14:54

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