Simple question

Here is the question:

(let [data [{:a 1 :b 2 :v true}  {:a 2 :b 5 :v true}  {:a 22 :b 7}  {:a 2 :b 5 :v false}]
      k :v]
  (filter (fn [m]
            (if k (m k) true))) data)

I got

[{:a 1, :b 2, :v true}
 {:a 2, :b 5, :v true}
 {:a 22, :b 7}
 {:a 2, :b 5, :v false}]

I wonder why {:a 2 :b 5 :v false} is still included even if :v has false value?

Your parentheses are likely not in the places where you want them to be. Your call to the function filter has only one argument, the function. data is not a parameter to filter at all. Instead it is the last expression in the body of the let expression, and so it is returned as the value of the let.

thanks. too many parens!

You will likely hear suggestions for many things that can be set up in an editor or IDE, but I would highly recommend that even if you don’t go all the way to things like parinfer or paredit, at least having an editor that you configure for showing the parenthesis, square bracket, or curly bracket that ‘matches’ the one that the cursor is on and/or next to, is very, very handy.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.