On Sat, Dec 15, 2012 at 3:58 PM, Peter West <peter.b.w...@gmail.com> wrote:

> But it can't, can it? In this context (apply f [i]) with respect to (f i)*
>  apply *has *side-effects*!
>

This doesn't really make any sense.  There are no side effects here.  I
think maybe you just don't understand what apply does.  Let me try to
explain it a different way.

Some functions, like +, are designed to take 1, 2, 3, 4, 5, or any number
of arguments.  You can write:
(+ 1 2)
(+ 1 2 3)
(+ 1 2 3 4)
(+ 1 2 3 4 5)
etc.
The "contract" for + is that it takes any number of numbers as an input.

One thing + can't do is add up the numbers in a list, at least not when
written in this way:
(+ [1 2 3 4 5])
This doesn't make any sense, because + is expecting numbers, and we passed
it a vector.

It might seem somewhat ironic that + can't take a list of numbers.
Obviously, it knows how to add a series of numbers, it just expects them to
be one after each other, as arguments, not all bundled up in a list.

If only we could delete those brackets around [1 2 3 4 5]...  If only we
had some sort of "adapter" that could take a list/vector of items, and pass
them in as multiple arguments to a function that was designed to take
multiple arguments...

That is what apply does.

(apply + [1 2 3 4 5]) turns into
(+ 1 2 3 4 5)

Similarly,
(apply str [\a \b \c \d]) turns into
(str \a \b \c \d)

-- 
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