I generally prefer to pass in a sequence rather than use a variable
number of arguments.  The only time variable arguments are really useful
is in functions like map (or maybe +) in which you rarely use more than
one (or two) arguments and it would be a pain to wrap the last argument
in a list.

e.g.
#+begin_src clojure
  (map (partial + 1) (list (range 10)))
#+end_src
would be very awkward but required without &rest

finally, explicitly wrapped sequences are more composable

just my opinions... -- Eric

Alan <a...@malloys.org> writes:

> I always write a function to take a single seq argument because it can
> also take varargs if I wrap them in a seq.
>
> (defn add [nums]
>   (reduce + nums))
>
> (add some-seq)
> (add [1 2 3 4 5])
>
> On Nov 19, 4:19 pm, Jarl Haggerty <fictivela...@gmail.com> wrote:
>> I always write a function to take varargs because it can also take a
>> list using apply.
>>
>> (+ 1 2 3 4 5)
>> (apply + [1 2 3 4 5])
>>
>> On Nov 15, 9:52 am, Chris <christopher.ma...@gmail.com> wrote:
>>
>> > If you have a function that needs to treat multiple arguments as a
>> > group, what forces drive you to represent this as a single sequence
>> > argument vs. an "&" argument?  To give a concrete example, why does
>> > "+" work like
>>
>> > (+ 1 2 3 4)
>>
>> > instead of
>>
>> > (+ [1 2 3 4])
>>
>> > Is it performance?  Aesthetics?  Composability concerns?  Not having
>> > to call "apply" all the time?
>>
>> > Thanks,
>> > Chris
>>
>>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to