The API Cheatsheet section on Lists seems to indicate that '() is a list constructor, just like (list), but I’ve found that in practice they’re not exactly the same. For example, given:
(def foo "a")
(def bar "b")
(def zip "c")
The following statement:
(apply str '(foo bar zip))
produces the output “foobarzip”, which I wouldn’t expect.
But the supposedly equivalent:
(apply str (list foo bar zip))
produces “abc”, as I’d expect.
What’s going on here? If there’s a “shorthand” for a list in Clojure (like {} for maps and [] for vectors), what is it?
In lisps,
'(likequote) quotes its arguments, i.e. preserves them pretty much exactly as written in their s-exp form, including not evaluating anything within.To put it another way
'(foo bar zip)creates a list containing the symbolsfoo,bar,zip; while(list foo bar zip)creates a list containing the values offoo,bar,zip. In the first case,strwill be converting the symbols themselves to strings and then concatenating them.As a demonstration of this: