#clojure log - Dec 06 2015

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

3:00 ben_vulpes: is creating a form in clojurescript really the only way to do file uploads?

3:00 i suppose it would be too easy if i could just jam the file input file into the POST array...

3:01 justin_smith: ben_vulpes: the way I did it was I googled "upload file javascript" and translated it to like 3 lines of interop

3:02 ben_vulpes: ootay

3:02 thanks justin_smith

3:03 justin_smith: np - it is straightforward, once you see a working example of the js api

3:04 (and iirc it does not need a form)

3:14 ben_vulpes: i'd just hoped to wire this into one of the more standard ajax libraries

3:14 justin_smith: yeah, we tied it into a websocket

3:16 ben_vulpes: blech

3:16 web tekmologee

3:54 irctc: hi

3:55 this a place to get help?

3:56 ianhedoesit: sure!

3:56 irctc: ok

3:56 (def response (http/get "http://hi.com"))

3:56 (keys response) returns this

3:57 (:status :headers :body :request-time :trace-redirects :orig-content-encoding)

3:57 ben_vulpes: justin_smith: i'd hoped that i wouldn't have to drop down, that cljs-ajax would actually handle this

3:57 irctc: (take 1 (keys response))

3:57 ben_vulpes: how is a javascript post more complex than a curl one-liner

3:57 irctc: returns :status

3:57 how can i see that value of :status?

3:57 ben_vulpes: (:status response)

3:57 ianhedoesit: (:status response)

3:57 aw

3:58 irctc: what is that called?

3:58 ben_vulpes: irctc: keys are functions of their maps

3:58 irctc: oh yeah! i recall reading that, ty

3:58 ben_vulpes: it doesn't work all the time

3:58 beware

3:58 and there are no types to save you

3:59 /s

3:59 irctc: ty

4:00 ianhedoesit: also, (response :status); (get response :status)

4:01 WickedShell: I'm looking through yourkit and I have almost a MB of memory (just in the early list of results)) of duplicate strings like "clojure.lang.numbers" and "java.lang.Object" is there anyway to get clojure to intern these whenever it creates them? I'm not sure why they are all strings on the stack. (memory is a problem for me on some target devices)

4:03 irctc: ok how can i get the :status in one line without using def?

4:03 ben_vulpes: (let [s (http...)] (:response s))

4:03 oddcully: (-> (http/get "...") :status)

4:03 ben_vulpes: slick

4:04 (:status (http/get "...")) << ?

4:04 actually i've seen the above eat stacktraces

4:05 oddcully: i assume, that http/get is some costly operation? and you might need more than just one key? so a let might be better

4:05 irctc: ty very very much

4:05 TEttinger: WickedShell: I'm guessing those may be for reflection at some point, even if you aren't using reflection they may be so it can or a jar that uses yours can

4:06 oddcully: ben_vulpes: -> is a macro. it has potential to mess with your mind

4:06 irctc: indeed -> is i recognise that though i don't know what it does yet

4:07 TEttinger: ,(-> 0 (inc) (inc) (inc))

4:07 clojurebot: 3

4:07 irctc: let binds the http/get to s, correct?

4:07 oddcully: irctc: if you find the doc strings to crips for your taste, have a look at conj.io - it helps me alot to see something used with example code

4:07 TEttinger: same there as (inc (inc (inc 0)))

4:07 ben_vulpes: (let [{:keys [status]} {:status "bar"}])

4:07 if we're playing golf

4:08 where that last map is the http call

4:08 irctc: ty for conj.io, needed that

4:09 oddcully: ,(-> 0 inc inc inc)

4:09 clojurebot: 3

4:09 irctc: theres an eval bot here?

4:10 TEttinger: I was wondering if that would work, heh oddcully

4:11 irctc: ok, why does (let [s (http/get "http://hi.com")] (:response s)) return nil?

4:12 TEttinger: ,(:blargl {:a 1})

4:12 clojurebot: nil

4:12 TEttinger: could be that there's no key for :response

4:12 irctc: got it! ty

4:12 TEttinger: could be that it's really a vector of maps, or a map of maps and only the inner ones have :response

4:13 (not sure how http lib works)

4:13 (the :response may actually be a valid key and it has a value of nil)

4:28 WickedShell: TEttinger, yeah looks like you're right its all from reflection...

4:28 I still hold that interning the string on reflection would be kinda nice though for memory reasons

4:30 although on further reflection it would probably slow down most reflection uses :/ (although I shouldn't be reflecting at all within my code, I know some libraries I use do)....

4:51 TEttinger, found a great solution: if you are using java 8 (I forget what update) you can run string deduplication during GC with the following args "-XX:+UseG1GC -XX:+UseStringDeduplication -XX:+PrintStringDeduplicationStatistics"

4:51 TEttinger: yessss neat

4:52 does it need the last arg, WickedShell?

4:52 WickedShell: TEttinger, no not at all, I just had it in so that I could see the stats

4:52 TEttinger: oh ok cool

4:53 WickedShell: I'm seeing it dedup around 853KB every GC, and I had a bunch of stuff get pulled out after the start of the repl/etc before ever launching the app

4:54 that does require the G1GC though, (I haven't had a problem with it, but I've never been picky about that kinda thing yet)

4:54 TEttinger: reducing memory usage successfully?

4:54 WickedShell: It's doing far better, but I need to see what that GC would do in general without the string dedup

4:55 TEttinger: try with just the arg "-XX:+UseG1GC"

4:55 WickedShell: I know I just need to finish doing it :D

4:55 TEttinger: hehe

4:55 WickedShell: IE I was GC'ing after hitting 1.5GB heap, now its taking me to around 500MB before GC'ing. (Which I'm fine with really)

5:00 TEttinger, yeah seems to have the desired effect, it vastly reduces my duplicated strings. The effect is moderately limited after the initial startup as most of the reflections that create it are still happening, and would be GC'd anyways, and since the dedup is only on GC it doesn't effect it till then

5:01 Supposedly for people's who apps are more string based (IE servers etc that do lots of http stuff) the effect can be fairly large/have almost all the benefits of interning without having to figure out/manage the interns as the programmer

5:02 I'm going to stick with it, and I'll see if I encounter a problem down the road, but since I was already stuck targeting JDK8 it doesn't adjust my requirements really

5:05 visof: hi guys

5:07 WickedShell: TEttinger, not from my app, but someone else's comparing java 7's parallel gc http://i.stack.imgur.com/rhmQ9.png vs java 8 G1GC with string dedup http://i.stack.imgur.com/tDWnV.png

5:08 I'm seeing similair behaviour here

5:16 visof: (partition-by identity '(1 1 2 3 4 4 1 1))

5:16 ,(partition-by identity '(1 1 2 3 4 4 1 1))

5:16 clojurebot: ((1 1) (2) (3) (4 4) (1 1))

5:16 visof: how can i do the same for some hashes for specific key?

5:17 , (partition-by identity '({:k 1} {:k 2} {:k 2} {:k 1} {:k 1}))

5:17 clojurebot: (({:k 1}) ({:k 2} {:k 2}) ({:k 1} {:k 1}))

5:18 visof: , (partition-by identity (map #(:k %) '({:k 1} {:k 2} {:k 2} {:k 1} {:k 1})))

5:18 clojurebot: ((1) (2 2) (1 1))

5:18 visof: but i need the original hash

5:18 not the values of the keys

5:19 can anybody help?

5:25 ARM9: ,(map keys '({:k 1} {:k 2} {:k 2} {:k 1} {:k 1})) ;visof

5:25 clojurebot: ((:k) (:k) (:k) (:k) (:k))

5:26 visof: ARM9: that's what i don't want

5:27 i want collect equal hashes in some specific keys without lossing the hash itself

5:27 opqdonut: ,(partition-by keys [{:k 1} {:k 2} {:k 2} {:k 1} {:k 1}]) -- like so?

5:27 clojurebot: (({:k 1} {:k 2} {:k 2} {:k 1} {:k 1}))

5:27 opqdonut: ,(partition-by keys [{:k 1} {:k 2} {:j 2} {:j 1} {:k 1}]) -- this is what I meant

5:27 clojurebot: (({:k 1} {:k 2}) ({:j 2} {:j 1}) ({:k 1}))

5:28 TEttinger: do you mean adding the values together for identical keys?

5:28 visof: '({:k 1} {:k 2} {:k 2} {:k 1} {:k 1}) should return (({:k 1}) ({:k 2} {:k 2}) ({:k 1} {:k 1}))

5:28 something like this

5:29 TEttinger: you had that

5:29 opqdonut: visof: you already tried (partition-by identity ...), wasn't thatexactly the right thing?

5:29 visof: opqdonut: nope

5:29 TEttinger: , (partition-by identity '({:k 1} {:k 2} {:k 2} {:k 1} {:k 1}))

5:29 oddcully: ,(partition-by :k '({:k 1} {:k 2} {:k 2} {:k 1} {:k 1}))

5:29 clojurebot: (({:k 1}) ({:k 2} {:k 2}) ({:k 1} {:k 1}))

5:29 (({:k 1}) ({:k 2} {:k 2}) ({:k 1} {:k 1}))

5:29 opqdonut: oddcully's solution works when you have other keys besides :k

5:30 ,(partition-by :k '({:k 1 :a 1} {:k 2 :b 2} {:k 2 :c 3} {:k 1} {:k 1 :d 4}))

5:30 clojurebot: (({:k 1, :a 1}) ({:k 2, :b 2} {:k 2, :c 3}) ({:k 1} {:k 1, :d 4}))

5:30 opqdonut: like so

5:30 TEttinger: I think that's not the goal, opqdonut. if I understand correctly, it's whole hash-maps being compared

5:31 opqdonut: but he did that already and wasn't satisfied with it :P

5:31 TEttinger: ,(partition-by identity '({:k 1} {:k 2} {:k 2} {:k 1} {:k 1} {:j 1 :l 2}))

5:31 clojurebot: (({:k 1}) ({:k 2} {:k 2}) ({:k 1} {:k 1}) ({:j 1, :l 2}))

6:01 visof: what is the best way to collect similiar things together ?

6:02 '(1 1 2 1 3 4) -> (1 1 1) (2) (3) (4)

6:02 oddcully: group-by? frequencies?

6:22 MJB47: ,(vals (group-by identity '(1 1 2 1 3 4))) ; visof does this work?

6:22 clojurebot: ([1 1 1] [2] [3] [4])

8:12 MONODA: for some reason: (= (c/complex-number 0.0) (c/complex-number -0.0)) returns false

8:12 this is definitely wrong, any ideas if I'm doing something incorrectly?

10:13 jonathanj: is there a neat way of writing this in Clojure: gen.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(new JcaDigestCalculatorProviderBuilder().build()).build(sha1Signer, new X509CertificateHolder(cert)));

10:14 i'm not sure if you can use (new) in a (..) form

10:21 ucb: I'm confused, I'm depending a project on a lib L, which depends on a lib L2. I'm trying to access L2 from within my project and I'm getting Not Found errors. Am I correct in thinking that if I add L in my :dependencies in leiningen, then L2 should be available too?

11:30 xeqi: ucb: yes, it will normally pull in L2 as well

11:31 ucb: xeqi: that's what I thought too, but when requiring an ns from L2, it can't be found. I'm wondering why :/

11:31 xeqi: does lein deps :tree show L2?

11:32 and the correct version of L2

11:32 ucb: it does not

11:32 very strange

11:35 xeqi: then either L does not say it requires L2, or the project.clj file is saying not to bring in L2. The later is easy to check, does the project.clj have any :exclusions in the tree?

11:35 ucb: the current project, and L are both mine

11:35 and I can tell you that L depends on L2 for sure, and that there are no exclusions anywhere

11:36 this is L

11:36 and this is L2 https://github.com/puniverse/pulsar/

11:36 my current project depends on [sliver "0.0.1-SNAPSHOT"]

12:16 xeqi: apparently I didn't deploy the right version of sliver; it's all good now

12:16 thanks for looking

13:14 favetelinguis: Is there something like Prolog _ in core.logic when i want to express any value is valid?

13:44 dnolen: favetelinguis: yes `fresh` makes new logic vars

13:44 `(fresh [_] ...)`

13:44 favetelinguis: thanks

14:37 weebz: has anyone had any experience with MMJ / sending sysex to midi devices with clojure?

14:37 or on OS X adding a jar to /Library/Java/Extensions?

14:37 I'm running into this error, and I'm not sure how to solve it

14:37 no mmj in java.library.path

16:00 ben_vulpes: so i'm uploading a file with xhrio via clojure.browser.net, and don't naively understand how to deserialize the file object in the k/v map i'm POSTing to the server -- justin_smith, any insight to offer?

16:01 justin_smith: ben_vulpes: accessing the file from the server side?

16:01 ben_vulpes: justin_smith: myeah

16:01 i'm using http-kit, so the whole map is coming in on the body. at this point i'm naively calling (slurp (.bytes (:body r))) just to see the map printed out to the repl

16:01 justin_smith: ben_vulpes: I know that with ring's wrap-upload you get a file on disk in /tmp

16:03 ben_vulpes: i might still be misusing xhr

16:05 http://dpaste.com/0XHWZFY

16:08 justin_smith: ben_vulpes: I am extremely suspicious of '(js->clj file)'

16:08 ben_vulpes: i have tried it both ways

16:09 sad hacking detritus

16:14 http://dpaste.com/0B1NZ7C << more detail

16:14 justin_smith: ben_vulpes: so that file should be your thing

16:15 * ben_vulpes looks into form decoding

16:15 ben_vulpes: justin_smith: myeah, that's what i'm given to understand. i don't quite grasp how to pull that out of a map-shaped string, though.

16:15 justin_smith: I mean it created a file object

16:16 ben_vulpes: riiiight. i think the cljs side of things is working now, i just need to understand how to turn that POST data into k/v pairs and a file object.

16:16 justin_smith: what is "net" there - are you sure it expects the clojure version of the file and not a js version?

16:18 because with the current state of that, I would not be super surprised if it was a "File" on the js side, but the server just got the str representation of a file (which is of course kind of useless)

16:18 ben_vulpes: good question

16:18 net is clojure.browser.net

16:19 it is showing up in string printing as #object[File [object File]]

16:25 well i fell back to form data and now i get java.io.File


16:26 justin_smith: cool, so that file should have the stuff you need, right

16:26 ben_vulpes: burned again by the law of leaky abstractions

16:27 right yeah. have yet to confirm it but i see java.io.file now which is what i'm looking for

16:27 thanks again justin_smith

16:27 justin_smith: np - I am sure this would have been different if json had a file representation (but of course it does not)

16:51 benjyz1: hi. how can i define a short-hand for a java-namespace?

16:51 justin_smith: no

16:51 benjyz1: (:import foo.bar)

16:51 (def fb foo.bar)

16:51 not a good idea?

16:52 justin_smith: you don't even need the import thought

16:52 but that's a class, not a package

16:52 benjyz1: I mean class

16:52 justin_smith: maybe I misunderstand what you mean by "namespace"

16:52 benjyz1: yes, that was confusing

16:53 justin_smith: well, the symbol you define won't work with the interop forms

16:53 ,(def d java.util.Date)

16:53 clojurebot: #'sandbox/d

16:53 justin_smith: ,(new d)

16:53 clojurebot: #error {\n :cause "Unable to resolve classname: d"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.IllegalArgumentException: Unable to resolve classname: d, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6891]}\n {:type java.lang.IllegalArgumentException\n :message "Unable to resolve classname: d"\n :at [clojure.lang....

16:53 justin_smith: ,(new java.util.Date)

16:53 clojurebot: #inst "2015-12-06T21:53:44.401-00:00"

16:53 justin_smith: so the def you make is mostly useless

16:53 TEttinger: benjyz1: do you mean something like renaming AbstractProxyFactoryBean to bean-thing ?

16:54 benjyz1: interesting...

16:54 justin_smith: you can use a def, but the def is pretty much useless, and you can't do a true rename

16:54 TEttinger: yeah, there's sorta workarounds

16:54 benjyz1: ok. are there are other ways to get a shorter name?

16:54 TEttinger: how's your macro writing skills?

16:54 justin_smith: just import

16:55 but really, all you need is a constructor with the name, otherwise you only need to worry about instance methods

16:55 (usually)

16:55 benjyz1: ok, I'm accessing static fields.. perhaps I'm confused about import

16:56 justin_smith: benjyz1: import doesn't do much, other than change the rules for class lookup, but import does not support any sort of renaming

16:58 benjyz1: ok, I'll try some macro.. I have a stack language in Java

17:07 ,(defmacro op [x] `(com.foo/~@x))

17:07 clojurebot: #<RuntimeException java.lang.RuntimeException: Invalid token: com.foo/>

17:08 benjyz1: com.foo is invalid token. hmmm..

17:09 justin_smith: it's not taken - it just doesn't resolve to anything that exists

17:09 oh, misread, sorry

17:10 benjyz1: I have a bunch of static fields of the com.foo class

17:11 which are opcodes of a language

17:22 idea someone how to do this?

17:22 https://www.refheap.com/112423

17:22 TEttinger: ,(defmacro op [x & args] `(. java.util.Math ~x ~@args))

17:22 justin_smith: benjyz1: macro splicing does not work at the symbol level

17:22 clojurebot: #'sandbox/op

17:23 TEttinger: ,(op PI)

17:23 clojurebot: #error {\n :cause "java.util.Math"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.ClassNotFoundException: java.util.Math, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6891]}\n {:type java.lang.ClassNotFoundException\n :message "java.util.Math"\n :at [java.net.URLClassLoader$1 run "URLClassLoader.java" 366]}]\n :tra...

17:23 TEttinger: mm.

17:23 lang

17:23 ,(defmacro op [x & args] `(. java.lang.Math ~x ~@args))

17:23 clojurebot: #'sandbox/op

17:23 TEttinger: ,(op PI)

17:23 clojurebot: 3.141592653589793

17:23 TEttinger: ,(op sin (op PI))

17:23 clojurebot: 1.2246467991473532E-16

17:23 justin_smith: but yeah, do it TEttinger 's way

17:24 benjyz1: thx. I've just recently worked with a clojure jython interpreter and it worked pretty well

17:25 https://github.com/rplevy/clojure-python

17:25 yonatankoren: I haven't done Clojure in a couple weeks, I'm going through withdrawals

17:26 benjyz1: TEttinger: thx

17:26 TEttinger: no prob, I am not very good with macros so I'm mostly pleased that it seems to work!

17:27 benjyz1: I'm trying it for my case, which is actually simpler, since it doesn't have any args

19:19 ben_vulpes: what's a concise way to turn a list of values into a map with keys that are those values and an arbitrary value on each key in the new map?

19:19 eg [1 2 3] -> {1 {} 2 {} 3 {}}

19:19 justin_smith: ,(zipmap [1 2 3] (repeat {}))

19:19 clojurebot: {1 {}, 2 {}, 3 {}}

19:20 ben_vulpes: noice

19:20 thanks justin_smith!

21:27 m00nlight: How can I export a function with default argument in clojure to be called in Java ?

21:29 justin_smith: m00nlight: if you have gen-class for the namespace, each argument list should be a separate method overload, based on argument count (both should take Object for each arg)

21:30 m00nlight: justin_smith: So I just to need to export two overloading methods in gen-class, right?

21:31 justin_smith: m00nlight: you shouldn't need to export at all, the functions in that namespace should all be accessible as static methods

21:33 m00nlight: justin_smith: Actually, I define which methods to gen for the class to be called in Java, so in this situation, I need to export two different methods, right?

21:33 justin_smith: I'm not sure, but if you don't mention the function at all, and its namespace is gen-class compiled, it should be accessible as a method for each arity it defines

21:35 m00nlight: justin_smith: http://pastebin.com/TK8FaM9Z

21:35 for this example, I want to export an overloading for generateVector

21:36 which could take another default empty list as input

21:36 in Java, in this case, I need to define two seperate methods in the :method of gen-class, right?

21:37 justin_smith: yes, I think so - argument count is a form of overloading, each count calls a different definition

21:37 m00nlight: justin_smith: OK. I will try, Thanks for your help :)

Logging service provided by n01se.net