Fork me on GitHub

How do you use any assets file that is provided by cljsjs package? I'm using leiningen.


@noisesmith I’d appreciate any help with maintaining liberator. I try to fix bugs and merge sensible improvements where I can, but my time is very limited. You’re welcome in #liberator to discuss what you’e missing.

Jim Rootham14:12:31

I have

(defn get-owner [db paper-id]
	let [query-string "SELECT user_id FROM papers WHERE paper_id=?"]
	(get (first (query db [query-string paper-id])) :user_id)
and it is telling me I cannot take the value of a macro. I have moved it around in the file so I don't think it is something outside that. What am I doing wrong?

Alex Miller (Clojure team)14:12:44

that let should be in parens

Jim Rootham15:12:36

Thank you, it is amazing what you cannot see sometimes.


What is the best way to write a function which will take a sequence like [[filter-fiction? true] [filter-hardback? false] [etc etc]] and produce a predicate fn which can be used to filter a sequence like [{:title foo :fiction? true :hardback? true} {etc}] such that if filter-fiction? is true, then only items where :fiction? is true will be returned.


I’m very new to clojure and to programming in general and can only come up with horribly messy solutions to this…


@noob a good first step would be to put that sequence into a hash-map, so you get easy lookup of each property


So it would look like {:filter-fiction? true ...}? I’m not sure how that helps, I know I want to loop through each filter, and if its true add it to the predicate fn that I pass to (filter pred coll) but I’m not sure how to do that in a clojury way…


in that case I'd imagine a combination of filter (to get the predicates), map (to get the right thing for each predicate) and every? to form the predicate


also symbols is a weird choice there, more typical would be keywords or strings - keywords are not just for keys in maps, they are for when you want something that unambiguously only stands for itself


Ah thanks that sounds promissing, I’ll have another go!


And yes I’m using strings for :title, should have put "foo"


I meant filter-fiction?


I assumed foo was something bound to a string


Oh yes I should have put :filter-fiction?`


Ok I’m still stuck… I want to write something like this (I know this isn’t syntactically correct)

(defn filter-books
  [filters books]
  (when (:fiction-filter? filters)
    books = (filter (:fiction? %) books))
  (when (:hardback-filter? filters)
    books = (filter (:hardback? %) books)))
but I know that won’t work in a functional language… I guess I don’t understand how to use map in this context..


@alex395 you can create new bindings by using let, and those bindings can refer to other previous bindings or shadow them (reuse the same name)


+user=> (let [filters []                                                                
      filters (if (even? 3)                                                     
                (conj filters :odd-input))                                      
      filters (if (> 3 10)                                                      
                (conj filters :small-input))]                                   
[:odd-input :small-input]


Ah I didn’t realise you could do that! Thanks for the help I think I’ve got it now 🙂

Drew Verlee23:12:27

So pomegranate somehow allows me to not have to restart cider/my repl. But its not clear how im supposed to add it to my ~/.lien/profile.clj as what exactly? A library? A plugin? Once this is setup correctly, i’m i supposed to do something special beyond adding libraries like normal in my project.clj? Do i need to run something like this example from the readme:

=> (use '[cemerick.pomegranate :only (add-dependencies)])
=> (add-dependencies :coordinates '[[incanter "1.2.3"]]
                     :repositories (merge cemerick.pomegranate.aether/maven-central
                                          {"clojars" ""}))
;...add-dependencies returns full dependency graph...
=> (require '(incanter core stats charts))


it's a library, you can add it as a normal dep