tags:

views:

83

answers:

1

With closure

(apply str [\a \b])

and

(apply str '(\a \b))

returns "ab".

(apply str (\a \b))

returns an error.

Why is that?

+11  A: 

Because (\a \b) means "call the function \a with an argument of \b", and since the character \a is not a function, it fails. Note the difference in the following:

user=> (+ 1 2 3)
6
user=> '(+ 1 2 3)
(+ 1 2 3)

As a general rule, if you want to write a literal sequence, use a vector instead of a quoted list since the quote will also stop evaluation of the parts inside the list, e.g.:

user=> [(+ 1 2) (+ 3 4)]
[3 7]
user=> '((+ 1 2) (+ 3 4))
((+ 1 2) (+ 3 4))
Alex Taggart