I'm running through some of the 4Clojure problems and hit some weird behavior with some of my code. Upon further investigation it seems the culprit was using the quote macro vs list function. Why does this matter in the code below, and why does it produce the incorrect result?
user=> (= (class '(/ 1 2)) (class (list / 1 2)))
true
user=> (def a '(/ 1 2))
#'user/a
user=> (def b (list / 1 2))
#'user/b
user=> (class a)
clojure.lang.PersistentList
user=> (class b)
clojure.lang.PersistentList
user=> (apply (first a) (rest a))
2
user=> (apply (first b) (rest b))
1/2
user=> (class (first a))
clojure.lang.Symbol
user=> (class (first b))
clojure.core$_SLASH_
'(/ 1 2)
is analogous to:
(list '/ 1 2)
When you don't quote /, you get its value, which is the built-in division function, rather than the symbol.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With