#clojure log - Dec 19 2015

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

1:12 lambda-11235: leiningen isn't recognizing my test.check dependency.

1:22 Nevermind, now it's working. For no apparent reason.

2:57 slester: hey, is there a way to stop a window opened by clojure from immediately closing at the end of a program? I wanna look at a visualization but it just turns off

2:57 closes immediately :(

3:26 felixn: anyone familiar with clojure.core.logic.fd? I want to see if a list a is smaller then list b. sort of like fd/bounded-listo. it should be possible to write my own, but I'm a bit out of my depths XD

3:51 amalloy: smaller like, has fewer elements?

3:52 that doesn't sound like a finite-domain thing, it sounds like general logic programming

4:11 felixn: amalloy: one of the two lists is constant throughout, so I realized it should be fine to just m/project the length of it, so I can just use fd/bounded-listo!

4:11 amalloy: sure, if one is constant that sounds fine

4:15 felixn: all this core.logic/.fd stuff is blowing my mind, and it's easy to use. just dug pretty deep into the logic.fd stuff, I think I have a slightly better grasp on something I didn't realize existed an hour ago heh

6:24 jonathanj: can i set the media-type of a request from liberator's :handle-exception handler?

6:25 for example, if the media-type was going to be "application/pdf" but now there's an exception, i need to change the media type

7:21 oracle123: how to use json in clojure jdbc with postgresql? I want to insert a column of type json.

11:34 BRODUS: any ideas on how I could write an expression that would effectively be (take-while-plus-the-failing-value ...)

11:46 dxlr8r: well, you could put in a for loop, and return the position

11:47 it will then return the last position of the "while" and you can add Ok1

11:47 +1

11:49 or you can use loop / recur

11:52 justin_smith: ,(defn take-while-plus-fail [p? [el & rem :as coll]] (lazy-seq (if (p? el) [el] (cons p (take-while-plus-fail p? rem)))))

11:52 clojurebot: #error {\n :cause "Unable to resolve symbol: p in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: p in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: p in this context"\n ...

11:52 justin_smith: ,(defn take-while-plus-fail [p? [el & rem :as coll]] (lazy-seq (if (p? el) [el] (cons el (take-while-plus-fail p? rem)))))

11:52 clojurebot: #'sandbox/take-while-plus-fail

11:53 justin_smith: ,(take-while-plus-fail even? [0 2 4 5 7])

11:53 clojurebot: (0)

11:53 justin_smith: hrm

11:54 ,(defn take-while-plus-fail [p? [el & rem :as coll]] (lazy-seq (if (p? el) (cons el (take-while-plus-fail p? rem) [el]))))

11:54 clojurebot: #'sandbox/take-while-plus-fail

11:54 justin_smith: ,(take-while-plus-fail even? [0 2 4 5 7])

11:54 clojurebot: #<ArityException clojure.lang.ArityException: Wrong number of args (3) passed to: core/cons--4090>

11:54 justin_smith: ,(defn take-while-plus-fail [p? [el & rem :as coll]] (lazy-seq (if (p? el) (cons el (take-while-plus-fail p? rem)) [el])))

11:54 clojurebot: #'sandbox/take-while-plus-fail

11:55 justin_smith: ,(take-while-plus-fail even? [0 2 4 5 7])

11:55 clojurebot: (0 2 4 5)

11:55 BRODUS: nice

13:06 any recommendations on profiling clojure code in emacs?

13:07 justin_smith: for micro-benchmarks, use criterium, for actual profiling use a java profiler, yourkit is excellent, but jvisualvm is free and comes with the jdk

13:09 BRODUS: justin_smith: thanks

13:15 lokien_: clj-refactor replacement for vim?

14:09 renart: any automated tools for identifying unused dependencies in project.clj? i've cluttered mine up something fierce.

14:13 justin_smith: renart: you could tru commenting out a dep followed by lein check, if lein check passes the dep was not being used

14:14 *try

14:14 renart: justin_smith: i'm going to bet that doing a manual traversal will be faster than enduring the clojure startup time.

14:15 justin_smith: renart: good luck, I don't know of any automated tool that even knows how to map namespaces to deps in project.clj, not to mention finding unused deps

14:15 * renart dives in

14:16 rhg135: Clojure actually starts reasonably fast

14:17 justin_smith: rhg135: but the plan I suggested requires starting lein repeatedly, that is not fast

14:17 rhg135: Oh right

14:27 ghost__: do people still reject using clojure for small programs, because "startup is too slow"?

14:28 rhg135: Not me. I'm writing scripts in it.

14:29 justin_smith: lein with nrepl is so easy to use, people never find out how much faster startup could be

14:30 rhg135: And less convenient, but for dev time I don't think it's a big deal

14:31 justin_smith: just today I created an uberjar with clojure.core, criterium, core.async, and prismatic/schema in order to have a repl with fast startup to hash out ideas in

14:31 rhg135: Like running javac also takes a while

14:31 justin_smith: right

14:32 renart: justin_smith, rhg135: compiling my own uberjar and jacking into that's faster/better?

14:32 justin_smith: renart: no jacking

14:32 * renart only gets around to hacking on the clojurestack occasionally, relies almost entirely on leiningen

14:32 justin_smith: renart: java -cp my-uber.jar clojure.main starts in ~1 second

14:33 renart: no hacking on the clojure stack - I just made a project with no source code, just a project.clj with the deps I want, then made an uberjar

14:33 rhg135: I'm writing a single file script but I do wonder what shebang to use

14:33 justin_smith: any uberjar that contains clojure.core can be run that way

14:33 renart: huh

14:33 so what's so slow about the leiningen boot up process?

14:34 justin_smith: renart: everything. It's equal parts lein itself, and nrepl last I checked

14:34 renart: hm

14:34 justin_smith: with clojure.main you can run a repl without nrepl

14:34 (or load and run an arbitrary clojure file, or whatever)

14:35 rhg135: #!/usr/bin/java -cp clojure.jar

14:35 rhg135: something like this

14:36 rhg135: I wanted to avoid distributing 2 files,but I thought so

14:37 Guess uberjar it is

14:38 justin_smith: rhg135: it is possible to make an uberjar runnable via shebang

14:38 as long as your -main is set up properly etc.

14:38 rhg135: Yeah

14:42 ghost__: justin_smith: how is it possible?

14:43 justin_smith: ghost__: https://coderwall.com/p/ssuaxa/how-to-make-a-jar-file-linux-executable

14:45 ghost__: justin_smith: and what should I have in main for this to work?

14:49 justin_smith: ghost__: -main should take any number of strings as arguments, and its namespace should be aot-compiled. Or you could set clojure.main as your main and it would just give you a repl.

14:50 ghost__: justin_smith: thank you

14:58 tolstoy: Interesting. I still have clojars problems. I can publish jars to the repo, but the pom.asc and jar.asc is denied. Wrong password or something? I've even associated the correct public key to my account (I think ... how would I know)?

14:59 justin_smith: tolstoy: for the asc, the password needed is your pgp key for signing with

14:59 not your clojars password

15:00 tolstoy: Right. I think it all works. I just get this:

15:00 Could not transfer artifact com.zentrope:quiescent:pom:0.2.2 from/to clojars (https://clojars.org/repo/): Access denied to: https://clojars.org/repo/com/zentrope/quiescent/0.2.2/quiescent-0.2.2.pom, ReasonPhrase: Forbidden.

15:01 justin_smith: what does that have to do with the asc files?

15:01 tolstoy: justin_smith: https://gist.github.com/zentrope/7c21bdb8d5de5e20a209

15:02 justin_smith: the asc files and the jar uploaded fine, the pom is the problem

15:02 tolstoy: The actual jars are there, but the metadata (?) that would make them show up in searches is not there.

15:03 justin_smith: right, it needs the pom file for search stuff I bet

15:03 tolstoy: For some reason, uploading the pom file seems to be forbidden.

15:03 justin_smith: yes, that's the only upload that failed

15:04 I am guessing there was something that went wrong previously, and led to a pom file that already exists that you don't have the rights to replace? that's weird though

15:04 tolstoy: My clojars password and username checks out (or I couldn't even get this far).

15:04 justin_smith: right, all the uploads except for the pom seem to have succeeded

15:04 tolstoy: Same with the signing stuff. If I enter wrong passwords, there's no attempt to publish.

15:05 justin_smith: yeah, sounds like an administration problem on the clojars end

15:06 tolstoy: I wonder if my public key must be published? (lein help gpg says it only matters if other people need it).

15:08 Trying again leads to the "redeploying non-snapshots" issue. Presumably the "pom" stuff would still work (given there are four separate requests).

15:14 justin_smith: Ah hah! It's the :pom-additions key in my project.clj file. Commented that out and it now works.

15:15 justin_smith: interesting

15:15 tolstoy: justin_smith: Clue was in here. https://github.com/clojars/clojars-web/issues/270

15:27 For some reason, "lein deps :verify" says my artifact has a bad signature. Oy.

15:28 justin_smith: tolstoy: pom.xml won't match pom.asc because you changed pom between generating the asc and the successful upload

15:28 tolstoy: I hope that's it. ;)

15:32 domgetter: I have a question about transducers: https://gist.github.com/domgetter/f50aa2cda6d4f8b0c6eb

15:32 Specifically about what (map inc) returns

15:32 justin_smith: ,(type (map inc))

15:33 clojurebot: clojure.core$map$fn__4537

15:33 justin_smith: it's a function, specifically a transducing function

15:33 domgetter: ,(((map inc) +) 1 2 3)

15:33 clojurebot: #error {\n :cause "Wrong number of args (2) passed to: core/inc"\n :via\n [{:type clojure.lang.ArityException\n :message "Wrong number of args (2) passed to: core/inc"\n :at [clojure.lang.AFn throwArity "AFn.java" 429]}]\n :trace\n [[clojure.lang.AFn throwArity "AFn.java" 429]\n [clojure.lang.AFn invoke "AFn.java" 36]\n [clojure.lang.AFn applyToHelper "AFn.java" 156]\n [clojure.lang.AFn app...

15:34 domgetter: I know (map inc) returns a function which takes a reducing function, and if I give THAT a reduction function, it returns a function that can take many things and reduce them with the reducing function and the original inc

15:37 Does (transduce (map inc) + '(1 2 3)) do something special?

15:38 Bronsa`: it invokes `reduce`

15:38 ,(reduce ((map inc) +) '(1 2 3))

15:38 clojurebot: 8

15:39 domgetter: ah okay

15:40 ah, so ((map inc) +) isn't a function I can just call, it's a function I can reduce with

15:40 that makes sense now, thank you

15:40 Bronsa`: ((map inc) +) is a reducing function

15:40 s/is/returns/

15:40 justin_smith: domgetter: you can call it, if you give it the right arguments

15:41 domgetter: justin_smith: If I call it the way reduce does?

15:41 Bronsa`: yes, if you called it with 1 2 rather than 1 2 3 it would have worked for example

15:41 because that's just the reducing arity

15:42 domgetter: Oh right, and then call it again with 4 3

15:42 justin_smith: ,((map inc) +) 1 2)

15:42 clojurebot: #object[clojure.core$map$fn__4537$fn__4538 0x612ce7b "clojure.core$map$fn__4537$fn__4538@612ce7b"]

15:42 justin_smith: oops

15:42 ,(((map inc) +) 1 2)

15:42 clojurebot: 4

15:42 Bronsa`: it only worked because map can reduce over more than one collection

15:42 but (inc 2 3) doesn't work

15:43 justin_smith: right

15:43 Bronsa`: ,(((map +) +) 1 2 3 4)

15:43 clojurebot: 10

16:06 domgetter: What would be considered more idiomatic? (reduce ((map inc) +) 0 [4 5 6]) or (transduce (map inc) + 0 [4 5 6]) ?

16:11 justin_smith: domgetter: the transduce one

16:12 BRODUS: ,(transduce (map inc) + 0 [4 5 6])

16:12 clojurebot: 18

16:15 domgetter: okay cool

16:22 rhg135: can anyone suggest good dev music?

16:26 BRODUS: rhg135: philip glass is nice

16:27 rhg135: hmm, thx

16:28 yenda: lately I usually like to listen to Infected Mushrooms, good for the flow :D

16:34 ridcully: i hope this is a band

16:34 justin_smith: ridcully: actually you just let some mushrooms rot and shove them in your ear holes

16:34 it's pretty neat, all the cool kids are doing it

16:35 rhg135: we have tons of those in the fridge

16:41 yenda: this is psytrance music :D

16:43 is there a way to pretty print an edn file in emacs like you would do with json-pretty-print-buffer ?

16:44 jkogut: rhg135, biosphere (Geir Jenssen)

16:50 BRODUS: anyone here familiar with the enlive library?

17:09 felixn: just would like to say I'm loving clojure XD core.logic & zip are awesome, and everything just feels simple. and I'm sure when I need them, the stateful idioms & async will be solid as well

17:15 ben_vulpes: yo justin_smith the cider parallel clj/s repls story seems to be working these days

17:16 dxlr8r: rhg135: pink floyd, wish you where here, etc.

17:16 ben_vulpes: granted i'm running 2 jvm's side-by-side, but i'm getting code sent to the browser via C-c C-k and code sent to the cljvm via the same combo entirely transparently.

17:17 i can't quite figure out how to get my reagent components to re-render yet, that's the next hurdle to clear in dwarfclojureforetress this weekend

17:22 yenda: ben_vulpes: do you have some readings on how you achieved that ? (the clj and cljs repl connexion and one shortcut)

17:32 ridcully: ben_vulpes: are we talking full blown df?

18:00 renart: ridcully: no, just that every time i dive into the clj/s tooling it's like playing dwarf fortress

18:00 * renart is also ben_vulpes on a different terminal

18:01 renart: it's kind of an in-joke with some other devs in my personalnet, regarding arcane knowledge entirely useless outside of the context in which it was originally won

18:02 ben_vulpes: yenda: tbqh i think it's just that cider's docs finally laid out how to configure everything

18:02 (and perhaps that cider now actually works[!])

18:02 the tl;dr is:

18:03 - M-x customize-group <RET> cider-cljs-repl (set this to weasel)

18:03 get weasel into your deps

18:03 - stick a weasel repl connect stanza in your main/equivalent in the clojurescript

18:04 M-x cider-jack-in-clojurescript

20:42 justin_smith: ben_vulpes: cool

20:54 ridcully: since 0.9 of catacumba, my [:prefix "secured" [:any #'check-login] ...] seems to get ignored. have i missed some breaking change?

21:21 RazorX-: clojure

21:30 chomwitt: a newbie question: all the tutorial i've read so far create a lein project but in project.clj the put handwritten versions of dependencies each time different! can i avoid that ?

21:31 justin_smith: chomwitt: you can use lein-ancient to find out the latest version of deps, but in the clojure world we don't typically specify dependencies without explicit versions

21:32 it might be possible, but probably isn't a good idea

21:33 chomwitt: justin_smith: ok. lein-ancient seems helpfull enough! i'll try it . thanks!

21:34 lein-ancient will find 'latest version' compatible with my installation , or latest latest ? :-)

21:35 justin_smith: what does "compatible with my installation" mean?

21:35 chomwitt: i mean if i have clojure 1.4 maybe latest ring-core wont work as good as a previous one ?

21:37 justin_smith: chomwitt: that's not how it works - your project.clj file decides which clojure version you get

21:37 lein ancient will tell you to pull in a newer clojure

21:38 I know it's a bit weird, but clojure itself is just another dep

21:38 chomwitt: justin_smith: but i have clojure already installed in my debian system

21:38 justin_smith: don't use that clojure

21:38 it's just a library

21:38 chomwitt: !

21:39 justin_smith: chomwitt: if you are using lein, I promise lein is not using that clojure version that debian installed

21:39 chomwitt: clojure is a java library that contains a bytecode compiler, it's a language as a library that runs on java

21:39 chomwitt: a! u r rigth. i have 1.6 installed and in a test project it says 1.7

21:40 justin_smith: chomwitt: the installed version is useful if you didn't want to use lein - if you just wanted to manually do dep management, and let debian control which jars you have

21:40 but that's the hard way to do it

21:40 lein is much easier, and it doesn't use any of your debian installed things, except for java itself

21:41 chomwitt: i definately follow the lein way! :-)

21:42 justin_smith: chomwitt: on the other hand, lein is a dev tool - once you have something to deploy, use lein to make an "uberjar" and just use that with java - end users or servers don't need to mess with lein

21:44 chomwitt: thanks for the clojure epiphany moment you offered me!! :-) i should have know that the mustache guy shouldnt be taken ligtly!! :-)

21:44 justin_smith: hah, no problem

21:45 chomwitt: it works out really nicely, but it's totally different from building C or python or ruby or js or... just about anything else I know of

21:45 I guess haskell has a slightly similar system, but not quite as radical as the clojure model in terms of dep isolation I don't think (at least not by most common usage)

21:52 * chomwitt trying lein-ancient

22:51 rhg135: I have a question. If I have {\a [1 2 3] \d [4 5 6] \c [7 8 9]} how can I get ([1 7 4] [1 7 5] [1 7 6] [1 8 4] ...)?

22:52 justin_smith: ,(map vector (vals {\a [1 2 3] \d [4 5 6] \c [7 8 9]}))

22:52 clojurebot: ([[1 2 3]] [[4 5 6]] [[7 8 9]])

22:52 justin_smith: ,(apply map vector (vals {\a [1 2 3] \d [4 5 6] \c [7 8 9]}))

22:52 clojurebot: ([1 4 7] [2 5 8] [3 6 9])

22:52 justin_smith: wait no that's not what you wanted at all :)

22:54 rhg135: yeah, I tried that. the tricky bit is order matters for this

22:55 justin_smith: rhg135: order based on keys or order based on vals?

22:56 rhg135: I have an a seq of keys

22:56 like, I have the map and [\a \c \d]

23:10 lambda-11235: ,(let [[xs ys zs] (vals (into (sorted-map) {\a [1 2 3] \d [4 5 6] \c [7 8 9]}))] (for [x xs y ys z zs] [x y z]))

23:10 clojurebot: ([1 7 4] [1 7 5] [1 7 6] [1 8 4] [1 8 5] ...)

23:12 lambda-11235: rhg135: It looks like converting to a sorted map will do the trick.

23:13 justin_smith: lambda-11235: another option is (map m (sort (vals m)))

23:13 err

23:13 I mean (map m (sort (keys m)))

23:15 rhg135: problem is thiss is not consistent ordering, but I think I got it

23:16 justin_smith: rhg135: then use (map m key-order)

23:16 rhg135: I got this https://www.refheap.com/112940

23:17 justin_smith: rhg135: (partial get m) is m

23:17 rhg135: seems not ram-friendly if distinct works like I think

23:17 oh doh! thx

23:18 justin_smith: rhg135: but with that use of destinct, eventually the function will hang forever

23:18 rhg135: how so?

23:19 justin_smith: because clojure doesn't know every result possible has been generated, so it will infinitely produce new combinations, all of which are deleted by distinct

23:19 rhg135: ah, II see

23:19 justin_smith: and there is no stop condition, so it will hang indefinitely

23:19 rhg135: I can't think of one though

23:20 well how to do it

23:20 justin_smith: rhg135: you can programmatically produce all the combinations - if you know the length of each val you can use the method of lambda-11235 above, otherwise it can be done with a recursive function calling mapcat

23:21 amalloy: rhg135: https://gist.github.com/amalloy/38295629f7b7ec3ca6ea

23:21 rhg135: I can get the length in O(1) so that works

23:22 ah

23:22 let me try that

23:25 amalloy: rhg135: that code is an application of a very common pattern in functional programming: exploring a decision tree (here, each entry in m is a node with 3 children) and creating a list of the options. you can use this same skeleton for a lot of functions if you see how they fit into the structure

23:26 ie, a doubly-nested for with recursion in the second binding

23:26 rhg135: yeah, I've seen this before, repeatedly

23:27 it seems to hang for me

23:28 amalloy: works for me on your example input

23:30 rhg135: it's not idle at least

23:31 justin_smith: http://i.imgur.com/K634Yg0.gif

23:31 rhg135: might just take a while, it's large

23:36 amalloy: now that I think it over, isn't that (map m order)?

23:37 amalloy: no

23:37 it's something like (mapcat #(map ... %) order)

23:39 rhg135: I'm sorry I don't see it. I guess I'm done for the day

23:40 amalloy: ,(for [x [1 2 3] y '[a b c]] [x y])

23:40 clojurebot: ([1 a] [1 b] [1 c] [2 a] [2 b] ...)

23:40 amalloy: this is just turning your map/order thing into that

23:43 rhg135: the code seems to add the vector at the key to the front

23:44 amalloy: in the same way that clojure.core/map does, because it conses onto the recursive call

23:46 rhg135: OH!

23:46 sheesh. I read for as let

23:47 I'm done

23:47 amalloy: the old classic (let [...] (let [...] )) joke

23:50 rhg135: I need a new font

23:57 idk why it wasn't working, but it is now

23:57 (inc amalloy)

23:57 sdegutis: (inc rhg135)

23:58 rhg135: ?

Logging service provided by n01se.net