Nested &REST parameter vs. single named parameter
- From: "Michael J. Forster" <mike@xxxxxxxxxxxxxx>
- Date: 12 Nov 2005 11:29:15 -0800
Hi,
As I understand it, I have two choices when defining a function to
accept an arbitrary number of inputs: a single named parameter
that takes an argument list, or a &REST parameter taking an
arbitrary number of arguments. Christopher C. Stacy said as
much in an earlier thread [1]:
Your function could either take &REST ARGS, or require the caller
to do the consing and your function takes a single LIST-OF-ARGS.
In any case, once you have consed up a list of args that need to
be applied to a function, you will of course want to use APPLY.
In another thread [2], Steven E. Harris suggested that this might be
just a matter of style, but that he found the choice of idiom
difficult. In that same thread, Barry Margolin responded:
It's just a convenience feature that allows for terser
function calls. There's no semantic difference between:
(defun fun1 (&rest args) ...)
(fun1 ...)
and
(defun fun2 (args) ...)
(fun2 (list ...))
Aside from the interaction of &REST parameters with &KEY
parameters, this choice does seem to be a matter of taste.
However, to me, the difference is further blurred when
comparing the implementations of WITH-GENSYMS by Paul
Graham [3]
(defmacro with-gensyms (syms &body body)
`(let ,(mapcar #'(lambda (s)
`(,s (gensym)))
syms)
,@body))
and Peter Seibel [4]
(defmacro with-gensysms ((&rest names) &body body)
`(let ,(loop for n in names collect `(,n (gensysm)))
,@body))
Both require me to pass the the arguments in a list
(with-gensyms (foo bar baz)
...)
Is there any reason to write ((&rest names) ...) instead of
(syms ...) in this example?
Thanks in advance,
Mike
--
Michael J. Forster
Shared Logic Inc.
.
- Follow-Ups:
- Re: Nested &REST parameter vs. single named parameter
- From: nepheles
- Re: Nested &REST parameter vs. single named parameter
- From: Peter Seibel
- Re: Nested &REST parameter vs. single named parameter
- From: Bill Atkins
- Re: Nested &REST parameter vs. single named parameter
- From: Michael J. Forster
- Re: Nested &REST parameter vs. single named parameter
- Prev by Date: Re: create a character or string from a character code
- Next by Date: Re: create a character or string from a character code
- Previous by thread: create a character or string from a character code
- Next by thread: Re: Nested &REST parameter vs. single named parameter
- Index(es):