Fork me on GitHub
#clojure
<
2015-07-19
>
malcolmsparks07:07:05

@kardan bidi guards are for filtering routes based on method, if no route matches you get a 404. 405 is a property of the resource, so if you want 405/406 you should use Liberator - yada will fully support 405/406 too

Pablo Fernandez08:07:24

Is there a better way of converting a hasmap into a sequence of pairs than (map vector (keys the-map) (vals the-map)) ?

ul08:07:22

(seq m) ?

ul08:07:57

hmmm clojurebot is strange

ul08:07:50

it was my fault, extra backticks

Pablo Fernandez08:07:36

What should I do if I want to push a modified version of a library to clojars to use it in one of my projects before my changes are accepted upstream and released?

canweriotnow09:07:40

@pupeno push it under your own namespace, e.g. pupeno/cool-project

canweriotnow09:07:08

There are instructions on clojars for doing that.

alqvist10:07:48

Anyone got a version of load-string/eval that works with a provided context? Like a map as a second argument

val_waeselynck10:07:15

@alqvist: well, you could wrap it in a let form maybe? like read the string, wrap it in a let, then eval

alqvist10:07:31

@val_waeselynck: like (let [c "text" e (read-string "c")] (eval e)

alqvist10:07:16

Unable to resolve symbol: c in this context

val_waeselynck10:07:14

no, more like (eval (list 'let '[c "text"] (read-string "c")))

val_waeselynck10:07:03

this may not be the most elegant way, but you get the idea

val_waeselynck10:07:15

@alqvist: more elgant imo: (let [context-bindings '[c "text"]] (eval `(let context-bindings (read-string "c"))))

alqvist10:07:14

@val_waeselynck thanks, I ended up with this (defn eval2 [context s] (let [context-bindings `['c context]] (eval `(let context-bindings (read-string s)))))

val_waeselynck10:07:58

@alqvist: how do you call it? I don't see what ['c context] is for

alqvist10:07:52

(eval2 {:id "woot"} "(:id c)")

alqvist11:07:17

Still got a problem though, if I have a list or a range in the context map I get an exception: ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn

alqvist11:07:29

Better brush up on my evaluation skills

alqvist11:07:42

But vectors work fine

val_waeselynck11:07:25

@alqvist: you'll want to quote context when calling eval2. E.g (eval2 '{:numbers (range 10)} "(count (:numbers c))")

val_waeselynck11:07:37

instead of (eval2 {:numbers (range 10)} "(count (:numbers c))")

Petrus Theron13:07:02

Does anyone have a simple configuration templating function lying around? E.g. given a template like "window.my_endpoint = "${API_ENDPOINT}", to replace the $ vars with data from a map or local environment vars?

alqvist13:07:47

@val_waeselynck: thanks for your help

val_waeselynck13:07:29

@alqvist: you're welcome simple_smile note that for your use case, dynamic vars may offer an advantage over let bindings: (def ^:dynamic c)

(binding [c {:id "woot"}]
   (eval (read-string"(:id c)")))

borkdude19:07:21

in clojure JVM, what's the difference when I do (go (println (.getId (Thread/currentThread)))), or (thread (println (.getId (Thread/currentThread))))

borkdude19:07:41

I notice that the go expression uses a new thread every time I evaluate it, and the thread expression re-uses the same thread

potetm19:07:22

@borkdude: There’s no functional difference. The difference is how the two are executed. The go expression is executed on a thread pre-allocated for go blocks. The thread expression is executed on a thread in an infinite threadpool.

borkdude19:07:22

@potetm: yeah, I was wondering about the 'how'. the thread pre-allocated for go-blocks, it seems to be different every time

rauh19:07:54

go uses fixed, thread uses cached

potetm19:07:55

@borkdude: Sorry, got excited and didn’t catch your actual question simple_smile

borkdude19:07:48

interesting, (dotimes [i 150] (go (println (.getId (Thread/currentThread))))) indeed seems to be limited to 100 different threads on my machine

rauh19:07:07

The reason: The go blocks will make sure that the threads aren't blocked (unless you do something silly in them) so that's why it was chosen this way around (can't know for sure but an educated guess)