#clojure log - May 10 2015

The Joy of Clojure
Main Clojure site
Google Group
List of all logged dates

0:00 airportyh: Hello all, I am learning about protocols. What are the common protocols that are built-in?

0:28 turbofail: derp. looks like i was too late. but in case anyone else is interested in airportyh's question see https://github.com/clojure/clojure/blob/master/src/clj/clojure/core/protocols.clj

0:36 justin_smith: (inc turbofail)

0:36 lazybot: ⇒ 6

3:15 cfleming: dnolen: Yeah, that might be - I have to revise that. I did the support originally for cljx, but it'll get much more use now. It's actually surprisingly tricky to do well.

3:37 goracio: hey there, lein figwhell reloads only client but what about reload of the server ? i have to re run - lein figwheel in that case each time

3:54 lein figwhell reloads only client but what about reload of the server ? i have to re run - lein figwheel in that case each time

4:08 dysfun: your server is written in clojure?

4:08 you can use ring.middleware.reload to reload code

4:10 goracio: yes server in clojure also

4:11 dysfun: then (:require [ring.middleware.reload :refer [wrap-reload]]) and (wrap-reload my-handler)

4:11 note that you should only do this in development

4:12 * dysfun has a middleware.clj which contains three functions, one for live, one for dev and one for both that's shared

4:13 goracio: and where should i require that ?

4:13 dysfun: depends how your app is structured

4:14 goracio: i guess in development-middleware

4:14 i use luminus template

4:14 dysfun: how long ago did you use the luminus template? i'm familiar with the old one but not the new one

4:14 the old one has a middleware.clj

4:14 goracio: i use new build

4:15 dysfun: anyway, wherever you're wrapping your middleware is the right place

4:15 i find it most convenient to have a function to call for dev and a function to call for live

4:15 goracio: https://gist.github.com/fellz/ecc473faac1e6ccb108c

4:16 dysfun: yeah, i'd put that in development-middleware

4:16 with the require in the ns form at the top

4:17 goracio: and then i added (wrap-reload handler) in development-middleware

4:17 dysfun: well you have an arrow form

4:17 so i'd just add a new line in it with 'wrap-reload' in it

4:17 goracio: so just wrap-reload ?

4:18 ah ok

4:18 dysfun: what does 'omlet' do?

4:19 escherize: backend service for making savory breakfast foods

4:19 goracio: well i am trying simple app - take some articles from db and show them on the page )

4:19 dysfun: with om, i'm guessing

4:19 goracio: with reagent

4:19 dysfun: heh

4:20 escherize: you might wanna try reagent

4:20 * dysfun has just moved from om to reagent

4:20 escherize: reagent is Noice.

4:20 goracio: well i cann't convert json from server to articles list

4:20 * dysfun is going to write a clojurescript binding to Ractive though

4:20 escherize: also it's the default luminus +cljs template.

4:21 is that the jquery one?

4:21 dysfun: you can easily convert json from the server to an articles list

4:21 goracio: i user cljs-ajax

4:21 dysfun: no, Ractive is the guardian's alternative to React. released around the same time. discovered it yesterday, looks cool

4:21 goracio: (GET "/articles" {

4:21 :handler articles-list

4:21 :error-handler error-handler})

4:21 something like this

4:22 escherize: goracio: please use a pastebin service? like refheap.com

4:22 goracio: ok

4:22 so response i get is ArrayMap

4:22 not a HashMap

4:22 escherize: So, what are the benefits of ractive > react?

4:23 dysfun: ractive has a bit of a different look at the world. you know how om and reagent have to do all the clojure mutable state stuff to improve react performance? well ractive enables you to do it directly

4:23 escherize: ,(type [])

4:23 clojurebot: clojure.lang.PersistentVector

4:23 escherize: ,(type {:a 1})

4:23 clojurebot: clojure.lang.PersistentArrayMap

4:24 dysfun: ractive has primitives for updating a render of a component, for example, where react would by default rerender

4:24 plus two way binding

4:25 escherize: actually dysfun, I use re-frame so I am insulated from the internals of that [ reagent -> component -> dom ] pipeline

4:26 dysfun: *shrug*

4:26 goracio: i don't recognise that syntax. what plugin are you using?

4:26 the :handler bit

4:26 goracio: cljs-ajax

4:26 escherize: have u ever checked out their readme? https://github.com/Day8/re-frame/

4:27 dysfun: goracio: are you definitely requesting JSON?

4:27 escherize: i've only just heard of it

4:27 goracio: dysfun: Accept:application/json, application/edn, application/transit+json, text/plain, text/html, */*

4:28 dysfun: hrm. can you check the server is returning json by pinging a request at it with curl?

4:28 goracio: and i got json

4:29 dysfun: *shrug* sounds like cljs-ajax is the problem

4:29 goracio: Content-Type: application/json; charset=utf-8

4:29 dysfun: i've been using test data so far embedded in my main cljs file, so i haven't had to deal with ajax yet

4:29 does the content look right?

4:29 goracio: yes it's json

4:30 dysfun: *shrug* i don't know how cljs-ajax works, sorry

4:30 escherize: goracio, you can check with this

4:30 https://gist.github.com/d629b6bd93ac00fa96fc

4:30 now you'll be printing the returns for articles.

4:30 dysfun: well, bar that typo, "resoonse" :)

4:30 escherize: derp

4:31 it compiled in my head

4:31 https://gist.github.com/6054ae88a0c987fd3e77

4:31 goracio: {"title":"Hello world !!! "}

4:31 (.log js/console (:title response))

4:31 returns nil

4:31 clojurebot: I don't understand.

4:32 * dysfun hands clojurebot a botsnack

4:32 escherize: when you log it, in the console, is it a map or a string?

4:32 ,(use 'clojure.core.match)

4:32 clojurebot: #error{:cause "Could not locate clojure/core/match__init.class or clojure/core/match.clj on classpath.", :via [{:type java.io.FileNotFoundException, :message "Could not locate clojure/core/match__init.class or clojure/core/match.clj on classpath.", :at [clojure.lang.RT load "RT.java" 449]}], :trace [[clojure.lang.RT load "RT.java" 449] [clojure.lang.RT load "RT.java" 412] [clojure.core$load$fn__54...

4:32 escherize: ,(use core.match)

4:32 clojurebot: #error{:cause "core.match", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.ClassNotFoundException: core.match, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyze "Compiler.java" 6543]} {:type java.lang.ClassNotFoundException, :message "core.match", :at [java.net.URLClassLoader$1 run "URLClassLoader.java" 366]}], :trace [[java.net.URLClassLoader$1 run "UR...

4:32 * dysfun uses (enable-console-print!)

4:32 escherize: ,(use 'core.match)

4:32 clojurebot: #error{:cause "Could not locate core/match__init.class or core/match.clj on classpath.", :via [{:type java.io.FileNotFoundException, :message "Could not locate core/match__init.class or core/match.clj on classpath.", :at [clojure.lang.RT load "RT.java" 449]}], :trace [[clojure.lang.RT load "RT.java" 449] [clojure.lang.RT load "RT.java" 412] [clojure.core$load$fn__5427 invoke "core.clj" 5862] [cloj...

4:32 escherize: damnit im sorry

4:32 goracio: cljs.core.PersistentArrayMap

4:32 it's this

4:33 dysfun: hrm, the bot should really pastebin those or something

4:33 goracio: ArrayMap

4:33 dysfun: ArrayMap is like a map

4:33 it just happens to be ordered

4:33 escherize: TIL

4:33 wait i notices something, goracio:

4:33 you said the map looks like {"title":"Hello world !!! "}

4:33 goracio: yep and it should give some value from (:title response)

4:34 escherize: ,(:title {"title":"Hello world !!! "})

4:34 dysfun: (see "sorted-map")

4:34 clojurebot: #<RuntimeException java.lang.RuntimeException: Invalid token: :>

4:35 escherize: I think it's a cljs map with keys that are strings

4:35 dysfun: i presume the colon is from familiarity with javascript :)

4:35 escherize: i copy pasted. :(

4:35 ,(:title {"title" "Hello world !!! "})

4:35 clojurebot: nil

4:35 dysfun: aha, the string keys

4:36 escherize: ,(get {"title" "Hello world !!! "} "title")

4:36 clojurebot: "Hello world !!! "

4:36 goracio: well i use :format {:json-kw

4:36 dysfun: well are they coming back as keywords or not?

4:37 goracio: that worked )

4:37 (get ....

4:38 escherize: yeah you should find a way to make them keywords if possible

4:38 goracio: there is option :keywordize? true

4:38 will try it

4:39 option is not working (

4:40 how to send in :edn format ?

4:40 i use wrap-restful-format

4:41 escherize: ,(-> {:a 1 :b 2} pr-str read-string)

4:42 clojurebot: {:a 1, :b 2}

5:09 escherize: Flex box from reagent: http://re-demo.s3-website-ap-southeast-2.amazonaws.com/

5:11 goracio: well what the best way to handle json api still ?

5:11 compojure-api ?

5:13 escherize: compojure-api is kind of complicated, but has tons of benefits.

5:14 goracio: well that stuff with cljs-ajax also not the best option

5:14 i guess

5:14 with all that conversions from string to keywords

5:15 Deraen: goracio: If you're having problems with cljs-ajax you could try cljs-http

5:18 goracio: ok will look at it

5:19 escherize: you could do the string -> keyword thing yourself

5:19 not the best idea but it's quick:

5:20 https://gist.github.com/764023fab0ac3be11440

5:22 goracio: ok

5:25 escherize: what the best way to display that arraymap ? with map or with for ?

5:26 escherize: you can print it to the console with (.log js/console <map-name>)

5:26 goracio: i mean in reagent

5:26 escherize: ohhh

5:26 [:pre (pr-str <array-map>)]

5:27 works wonders

5:27 I have another way too, sec

5:27 I wrote this for a toy project

5:28 https://gist.github.com/e1fe925e5af4eb52ce99

5:28 goracio: i saw this style https://gist.github.com/fellz/416942e5e22191075e6b

5:29 escherize: did you want to see the text representation of the map, or display its contents?

5:29 goracio: display contents

5:29 list of articles in this case

5:30 escherize: you can use either.

5:30 goracio: article has title author subject and _id

5:34 escherize: undeclared variable table

5:35 i guess it's recursion

5:41 escherize: it doesn't work i have 2 articles so it's arraymap and then each article also arraymap

5:54 escherize: goracio: you mean you have a structure like [{:a 1} {:a 2}] ?

6:12 goracio: escherize: yep

6:58 supersym: do we have anything that can support a notion of 'shorthand' paths e.g. [:a :b [:c :d]] becomes [:a :b :c] and [:a :b :d] (potentially nested deeper ofc)

6:58 like a flatten/combinations mix I guess

7:35 irctc: Hi I'm baffled why

7:35 (let [] (map println #{1 2}) (map println #{}))

7:35 doesn't print anything

7:36 at all!

7:37 puredanger: map is lazy and you didn't realize it

7:38 irctc: oh shit

7:38 puredanger: Wrap doall or dorun around it to realize

7:38 irctc: ok

7:38 thanks guys

7:39 mnngfltg: irctc, `map` just returns a LazySeq and doesn't automatically realize it

7:40 irctc: btw is there a macro to realize a sequence

7:40 that i can use just outside of a map

7:42 mnngfltg: irctc, doall?

7:43 irctc: hmmmm

7:43 ok thanks people

7:43 :)

7:43 LnL: I have an issue with vendor prefixing in garden, has anybody here used it before?

7:45 Is there a way to do `{:display #{"flex" "-webkit-flex"}}` but with the builtin prefixing

8:19 andrew_: Hi all! Why it is not possible to see output if launching a .clj script with 'java ...' command?

8:41 gfredericks: andrew_: what does "output" mean?

8:42 justin_smith: that makes me feel all patriotic https://www.youtube.com/watch?v=lyHSjv9gxlE

8:48 kaiyin: https://gist.github.com/kindlychung/91199d72b031ff8c2c95 Isn't it a bit disturbing that [node value] is repeated multiple times?

8:49 andrew_: gfredericks: side effect of println. Actually solved te issue: goo.gl/YjT2rc

8:52 gfredericks: ah yeah

8:52 kaiyin: not if you like it always being lexically obvious where things come from

8:54 kaiyin: gfredericks: that should be a problem if you see defmulti-defmethod-defmethod... as a whole entity.

8:54 shouldn't

8:55 gfredericks: kaiyin: well, you could write a macro to dry it up if that's your preference

8:56 Glenjamin: if you want a whole entity

8:56 use case / cond

8:56 gfredericks: or condp

8:56 Glenjamin: the idea with multimethods is they're open to extension from anywhere

8:57 kaiyin: Glenjamin: Ah, I see.

9:07 how do you remove a multimethod in the repl?

9:20 why do we need #' prefix for the dispatch function? https://gist.github.com/kindlychung/bfc4cbad0b01a866b452

9:34 gfredericks: kaiyin: because multimethods don't let you update the dispatch function; so #' works around that with indirection

9:35 kaiyin: gfredericks: what does #' do exactly?

9:36 justin_smith: gfredericks: that punch at the end really does it

9:37 ,'#'+ ; kaiyin

9:37 clojurebot: (var +)

9:38 gfredericks: now I wish that talk I did on vars was recorded

9:38 kaiyin: ,(var var)

9:38 clojurebot: #error{:cause "Unable to resolve var: var in this context", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.RuntimeException: Unable to resolve var: var in this context, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6740]} {:type java.lang.RuntimeException, :message "Unable to resolve var: var in this context", :at [clojure.lang.Ut...

9:39 gfredericks: ,(var var var var var chex var)

9:39 clojurebot: #error{:cause "Unable to resolve var: var in this context", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.RuntimeException: Unable to resolve var: var in this context, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6740]} {:type java.lang.RuntimeException, :message "Unable to resolve var: var in this context", :at [clojure.lang.Ut...

9:39 gfredericks: ,(quote)

9:39 clojurebot: nil

9:39 gfredericks: sorry am being unhelpful

9:39 kaiyin: vars are the houses your functions live in

9:39 sort of

9:40 kaiyin: ok

9:40 how does that solve the updating problem?

9:40 justin_smith: kaiyin: a namespace is a collection of vars

9:40 kaiyin: ok

9:40 gfredericks: kaiyin: a var can pretend to be a function by proxying the call to the function it's housing

9:40 justin_smith: when you pass the var rather than the value of the var, when the namespace changes, the thing sees the new value in the namespace

9:42 (the one gotcha being if you destroy and recreate the namespace, like clojure.tools.namespace can do, this stops working - because there is actually a different var created)

9:42 kaiyin: in other words, the var always points to the lastest version of the function.

9:42 justin_smith: right

9:42 gfredericks: indeed; almost by definition

9:43 justin_smith: kaiyin: another way to see it - def alters the value of the var, if you want a new def / defn call to change your other code, referring to the var helps

9:43 kaiyin: ok, got it.

10:04 gfredericks: most of the time it's not necessary though

10:20 michaelr`: hi

10:20 Is this a known problem that an uberjar would start especially slow on osx?

10:39 justin_smith: michaelr`: I'd suspect some delay in acquiring a resource

10:56 also, you could use jstack to find out what it's doing when it is taking so long

14:52 TimMc: clojurebot: offline development |is| http://lolnein.com/2013/09/25/withoutinternet/ (semi-NSFW)

14:52 clojurebot: Roger.

15:28 kaiyin: https://gist.github.com/kindlychung/97bf9b74daf0230ea4f6 I am thinking that this way of generating dispatching keywords could go very wrong. e.g. tag1 is :a , type1 is :b.c tag2 is :a.b , type2 is :c

15:30 patrkris: hi folks. is there a predicate somewhere or an idiomatic/easy way to test whether two sets are disjoint?

15:35 kaiyin: ,(def s1 #{1 2 3})

15:35 clojurebot: #'sandbox/s1

15:35 kaiyin: ,(def s2 #{4 5 6})

15:35 clojurebot: #'sandbox/s2

15:36 kaiyin: ,(every? #(= % nil) (map s1 s2))

15:36 clojurebot: true

15:36 kaiyin: patrkris: ^ my two cents.

15:36 patrkris: kaiyin: thanks :)

15:38 oddcully: s/#(= % nil)/nil?/

15:38 Bronsa: kaiyin: that won't work if the set contains `nil`

15:39 patrkris: (comp empty? clojure.set/intersection) should do it

15:40 patrkris: Bronsa: ah of course... thanks

15:40 :)

15:40 oddcully: ,(empty? (clojure.set/intersection #{nil 1 2} #{4 5 6}))

15:40 clojurebot: #error{:cause "clojure.set", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.ClassNotFoundException: clojure.set, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6740]} {:type java.lang.ClassNotFoundException, :message "clojure.set", :at [java.net.URLClassLoader$1 run "URLClassLoader.java" 366]}], :trace [[java.net.URLClassLoader$1 r...

15:40 oddcully: oh... too late anyway

15:42 kaiyin: Bronsa: yeah, that's much better.

15:45 Is there a way to make the repl automatically use pprint every time it prints something?

16:34 dumptruck: hello

16:35 i am trying to use a java class annotation in clojure

16:35 it looks like gen-class is capable of this but i can't find very much documentation

16:35 in particular, i'm not sure of the structure for the metadata on the :name

16:36 (gen-class :name ^{somethinghere} com.whatever.Classname)

16:37 it appears to be a map which is pretty self explanatory... but I want to add an annotation which would look like this in java: @Plugin(id = "theid", name = "thename")

16:38 which i would imagine goes like so: (gen-class :name ^{Plugin {id "theid" name "thename"}} com.whatever.Classname)

16:38 but my ide is complaining about id

16:41 does it need to be ^{Plugin {:id "theid" :name "thename"}}

17:41 x1n4u: (map '(1 2 3) '(4 5 6))

17:41 ,(map '(1 2 3) '(4 5 6))

17:41 clojurebot: #<ClassCastException java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.IFn>

17:46 justin_smith: x1n4u: map needs a function

17:47 oddcully: (inc Bronsa) ; dijoint

17:47 lazybot: ⇒ 110

18:03 crazydiamond: Hi. I'm trying to delete and create Datomic database at a heat. But after creation when I "connect" to the URI it fails with error "database does not exist". But in console I see the database after delete/create sequence. Can anyone suggest, should I add some "sync" command to it or whatever? http://dpaste.com/1A4GW5X

18:05 bensu: crazydiamond: my solution to that problem was to add a timeout

18:05 crazydiamond: bensu, interesting

18:06 bensu: crazydiamond: I don't remember correctly but it was longer than expected and not very reliable

18:06 crazydiamond: yes, seems like that. cause in command line it was already done with timeout

18:06 like 0.5-1 sec

18:06 for me to type next command

18:07 bensu: yeah, I'm not sure but my timeout was over 2sec

18:07 crazydiamond: I wonder what should happen

18:07 dlau: what is the difference between (mapv #({:a %}) ["foo" "bar"]) vs (mapv (fn [v] {:a v}) ["foo" "bar"]) ? i feel like im misunderstanding the function macro :l

18:07 bensu: after trying a couple of times

18:08 justin_smith: ,'#{:a %}

18:08 bensu: dlau: the first one thinks {} is a function

18:08 clojurebot: #{% :a}

18:08 crazydiamond: dlau, if you write #({:a %})

18:08 justin_smith: err

18:08 ,'(#{:a %})

18:08 clojurebot: (#{% :a})

18:08 crazydiamond: it would run map {} as a function

18:08 justin_smith: ,'#({:a %})

18:08 clojurebot: (fn* [p1__73#] ({:a p1__73#}))

18:08 justin_smith: that's the one I wanted

18:08 note how it is calling the hash map with no args

18:08 crazydiamond: dlau, use rather #(do {:a %})

18:09 justin_smith: use fn

18:09 crazydiamond: dlau, "do" is one way to understand function macro better :-)

18:10 dlau: oh

18:10 woah that bot is cool O.O

18:12 great thanks so much, I thought #({}) would return a function hehe

18:14 justin_smith: it does, it's just a function that calls a hash map with no arguments

18:16 ,(#({:a 0}) :a)

18:16 clojurebot: #error{:cause "Wrong number of args (1) passed to: sandbox/eval98/fn--99", :via [{:type clojure.lang.ArityException, :message "Wrong number of args (1) passed to: sandbox/eval98/fn--99", :at [clojure.lang.AFn throwArity "AFn.java" 429]}], :trace [[clojure.lang.AFn throwArity "AFn.java" 429] [clojure.lang.AFn invoke "AFn.java" 32] [sandbox$eval98 invoke "NO_SOURCE_FILE" 0] [clojure.lang.Compiler ev...

18:16 justin_smith: oops

18:16 ,(#({:a 0} :a))

18:16 clojurebot: 0

18:17 oddcully: ,(map :a {:a 0})

18:17 clojurebot: (nil)

18:23 whodidthis: whats a fun way to add mime types to files served with ring.middleware.resource/wrap-resource

18:33 found it

18:43 Raynes: TEttinger2: Yo

18:44 gfredericks: yo

18:45 Raynes: yo

19:09 xzilend: For a clojure app that pulls data from an API and puts it into redis, would you prefer to have a constantly running app with an internal scheduler, or a tight app ran with cron?

19:23 mavbozo_: xzilend, constantly running app

19:24 xzilend, i prefer doing as many as possible in clojure

19:46 underplank: Hey all.. Anybody know if you can use the scratch-buffer in emacs to execute s-expr in cider using C-x C-e?

19:59 escherize: Has anyone here used re-com? https://news.ycombinator.com/item?id=9521955

20:00 it's a component library on top of reagent

20:23 gfredericks: underplank: I do that all the time, I just have to switch it to clojure-mode

20:29 underplank: gfredericks: ahh… I thought it might be something like that… so M-x clojure-mode ?

20:30 gfredericks: underplank: yep

20:30 which turns on cider mode for me, not sure if that's normal

20:30 underplank: gfredericks: ahh. ok… i’ll have a look.. I can always flick that on as well.

21:51 justin_smith: gfredericks: cider installs a hook on clojure mode

22:09 underplank: So I have a ring handler. And I want to initiate a webhook only AFTER the response has been returned by the ring hander. I could spawn a future with a delay in the middle of the handler but this seems not great. Is they anyway I can attach an event to the return of a function?

22:11 justin_smith: underplank: middleware can easily do some action after the wrapped function (but it should usually return or modify the value the wrapped function returned)

22:12 underplank: justin_smith: hmm yeah I thought about that. Would you basically just pass something back from the handler in the return function that the middle ware would pick up?

22:12 sorry return data

22:12 justin_smith: sure, if it needed some extra input beyond what the handler returned

22:14 underplank: ok. that might work.thanks!

22:34 wei: Has anyone used Om or Reagent with react-bootstrap? I’m trying to implement a popover

23:09 jdkealy: anyone ever run into an issue of serving javascript and css at non-https path and getting insecure link errors ?

23:09 sorry wrong chan ...

Logging service provided by n01se.net