Question

I am curious why the first argument to apply (and also reduce) affects the function's behavior as shown in the following code snippet.

user=> (apply conj '() [1 2 3])
(3 2 1)
user=> (apply conj [] [1 2 3])
[1 2 3]

user=> (apply conj '() '(1 2 3))
(3 2 1)
user=> (apply conj [] '(1 2 3))
[1 2 3]
Was it helpful?

Solution

It's not apply or reduce modifying the behaviour of conj. conj itself is polymorphic. It adds the elements in the most efficient way of the given data structure.

OTHER TIPS

Your question is about the behavior of conj not the behavior of apply.

Conj adds items to the front of lists and to the end of vectors.

See: http://clojure.org/data_structures

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top