Fork me on GitHub
#beginners
<
2017-12-31
>
boldaslove15600:12:19

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

ordnungswidrig10:12:49

@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?

alexmiller14:12:44

that let should be in parens

alexmiller14:12:01

(let [ ... ] ... )

Jim Rootham15:12:36

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

alexdavis21:12:12

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.

alexdavis21:12:35

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

noisesmith21:12:13

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

alexdavis21:12:06

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…

noisesmith21:12:09

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

noisesmith21:12:29

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

alexdavis21:12:34

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

alexdavis21:12:14

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

noisesmith21:12:29

I meant filter-fiction?

noisesmith21:12:37

I assumed foo was something bound to a string

alexdavis21:12:44

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

alexdavis22:12:42

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..

noisesmith22:12:13

@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)

noisesmith22:12:41

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

alexdavis22:12:08

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

drewverlee23: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)])
nil
=> (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))
nil

noisesmith23:12:17

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