Why we can write
(defn factory-foo [] (fn [] (println "foo")))
(apply (factory-foo) [])
but not:
(defn factory-bar [] #((println "bar")))
(apply (factory-bar ) []) ;throws NPE
Is this a bug?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
#((println "bar))is translated by the reader to(fn [] ((println "bar")))– note the extra parentheses.(println "bar")here printsbarand returnsnil, and thennilitself is called as a function because of the outer parentheses.nilisnullin fact, and an attempt to dereference it results to NPE.To avoid this just drop extra pair of parentheses inside
#(..):#(println "bar").