[comp.emacs] Unwrapping lists, or nested &rest arguments

bjaspan@ATHENA.MIT.EDU ("Barr3y Jaspan") (02/16/91)

I want to write a wrapper for call-process that does some frobbing
with process-environment before starting the process.  For example:

(defun frob-call-process (program &optional infile buf-or-name dsp &rest args)
  "Exactly like call-process except that frob-environment is added to
the processes environment."
  (let ((process-environment (append frob-environment process-environment)))
    (call-process program infile buf-or-name dsp args)))

This, however, does not work.  The &rest args in frob-call-process are
collected into a single list of strings, so call-process ends up
getting a single argument in ARGS, a list, whereas it requires a
series of arguments, all of which must be strings.  I have been unable
to think of a way around the problem and hope that I am missing
something obvious.  (Perhaps I should look into macros, but I've never
used them before.)

There are a couple possible solutions.

(1) Inventing some way of "unlisting" a list so that, for example, I
could pass (unlist args) as the last argument to call-process; then,
call-process would get a list of strings (the elements of args)
instead of a list with one element, a list of strings.  This would be
pretty wild and not necessarily even a good idea.

(2) Changing call-process so that it accepts strings OR lists of
strings (or, I suppose, lists of lists of strings, or ...) and expands
all the lists itself into one big list of strings, which it then
passes to exec using whatever mechanism it currently does.  This
strikes me as The Right Thing.

(3) Exporting another interface to the call-process mechanism that
does the same as (2) without actually changing call-process.

Thanks.

Barr3y Jaspan, bjaspan@mit.edu

bjaspan@ATHENA.MIT.EDU ("Barr3y Jaspan") (02/16/91)

Gack!  I forgot all about apply, which obviously does exactly what I
want.

Oh well.

Barr3y