Reputation: 45
(defn counttrue [val]
(count (filter identity '(val))))
It has something to do with how I'm calling it from the list, of this I'm sure. Because when I run
(count (filter identity '(1 2 3 true true false nil)))
It works just fine. Some how between defn and calculating I am missing something.
I've also tried running it with #(if % %) '(val) And I get the same answer.
I've seen similar code on this site but nothing that answers this particular question. Am I just calling val wrong?
Upvotes: 0
Views: 65
Reputation: 3612
'(val)
is a list of exactly one element: the original list. Try:
(defn counttrue [val]
(count (filter identity val)))
Then:
(counttrue '(1 2 3 true true false nil))
Upvotes: 1