#clojure log - May 10 2016

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

0:35 TEttinger: ...yeah screw Kotlin. apparently I'm hitting a compiler bug that is scheduled to be fixed in 1.0.2, but there's no workaround currently?

0:50 tolstoy: Maybe just make a small inlein (or whatever) script and try the hardest problem and see what it looks like?

0:57 TEttinger: I guess. trying to remember what inlein is

0:58 ah, windows may make that tricky :)

1:02 tolstoy: Ah.

1:03 I guess I was advising what I wish I did more often: timebox a bit on the hardest problem and see what it looks like.

1:03 Helps if you know the problem, I guess.

1:54 ilevd: dysfun, mpg raise an error java.lang.IllegalArgumentException: No matching clause: int4 then I'm trying insert {:a 1 :b 2} to jsonb field

1:54 *when

2:03 dysfun: ilevd: hrm?

2:04 paste code?

2:05 ilevd: (reference.data.pages/add-page (:jdbc t1) "4" "class" "url" {:a 1 :b 2} )

2:05 IllegalArgumentException No matching clause: int4 mpg.data/patch/fn--19517 (data.clj:47)

2:06 (insert! jdbc :pages {:url url

2:06 :type type

2:06 :content content

2:06 :full_name url

2:06 :version_id version-id}))

2:06 dysfun: can you pastebin enough code that i can make it fail please?

2:07 ilevd: Sec

2:09 dysfun: and i have literally just woken up, so bear with me :)

2:11 amalloy: you have a (case ...), where the value being dispatched on is "int4", or something that prints like that, and there's no clause in the case matching it

2:14 dysfun: thing is, as that's during insertion, it should be taking the type (against which the case is performed) from jdbc

2:15 https://github.com/mpg-project/mpg/blob/master/src/mpg/data.clj#L47

2:17 the only way i could see that failing was if you tried to shove a map in an int column

3:13 ilevd: dysfun, https://www.refheap.com/118885

3:14 Something wrong with order when using jsonb

3:17 dysfun: thanks, let me play with it a bit

3:17 ilevd: *without "references .."

3:30 dysfun: sorry, what precisely is 'jdbc' here?

3:30 i wrapped the clojure.java.jdbc api so i didn't have to deal with all the intricacies

3:32 ilevd: #reference.components.jdbc.JDBC{:config {:subprotocol "postgresql",

3:32 :subname "//localhost:5432/db",

3:32 :classname "org.postgresql.Driver",

3:32 :user "user",

3:32 :password "pass",

3:32 :stringtype "unspecified"},

3:32 :conn {:datasource #object[com.mchange.v2.c3p0.ComboPooledDataSource

3:32 0x28be5ba2

3:32 "com.mchange.v2.c3p0.ComboPooledDataSource[ identityToken -> z8kfsx9g16hbakekppxyi|28be5ba2, dataSourceName -> z8kfsx9g16hbakekppxyi|28be5ba2 ]"]}}

3:32 luma: please use pastebin or similar instead of pasting directly to the channel

3:32 dysfun: okay, in future please pastebin anything longer than a couple of lines

3:33 ilevd: Ok)

3:33 dysfun: https://gist.github.com/jjl/0f71cbbecf8169d51366aaf624c31ae9

3:34 this is why i find jdbc infuriating

3:39 namra: greetings

3:39 ronbonert: no u

3:45 namra: i want to write some tests for an http api that uses compojure as a routing library and ring-mock to mock http requests but i get the following error (with example code): http://pastebin.com/7Eric6SK

3:53 kwladyka: namra as i see you try to mock the route, you should use some url to also test a route. Like in the original example https://github.com/ring-clojure/ring-mock

3:54 namra just see what request return, it will help you a lot

3:54 namra: kwladyka: thanks alot

3:55 but the problem was caused by a (reload!)

3:55 running 'lein ring server'

3:55 and as soon as i change something and do a reload

3:55 the tests fail with that error

4:05 * dysfun swears at jdbc

4:06 hamid: :O

4:11 dysfun: how is it that postgres can have versions of every docs ever live for the database but only HEAD docs for the jdbc bindings?

4:12 i mean who the hell is deploying an under-development release of postgres to production?

4:12 or the jdbc drivers even

9:38 Rovanion: A function of mine takes a map. I want to check if the map contains a key - and then replace it with something else - before passing on the map. So (when (contains? map :key) do what exactly?)

9:40 ridcully_: you want to replace the key or the value?

9:41 Rovanion: The value.

9:41 ridcully_: assoc

9:41 Rovanion: Thanks!

9:43 ridcully_: but note, when using `when` you return nil, if the key is not there

9:48 justin_smith: yeah, (if (contains? m k) (assoc m k v) m) is probably what you want

9:49 Rovanion: Yes, that looks more like it. Thank you both!

9:50 justin_smith: ,(let [m {:a 0}] (cond-> m (contains? m :a) (assoc :a :foo) (contains? m :b) (assoc :b :bar))) ; if you are doing this with multiple keys

9:50 clojurebot: {:a :foo}

9:53 Rovanion: Ah, a chaining of conditions all evaluated independently.

9:54 justin_smith: the conditions are independent, but the transforms are additive (if applied)

9:54 ,(let [m {:a 0 :b 1 :c 2}] (cond-> m (contains? m :a) (assoc :a :foo) (contains? m :b) (assoc :b :bar))) ; if you are doing this with multiple keys

9:54 clojurebot: {:a :foo, :b :bar, :c 2}

9:55 Rovanion: Cool

9:56 abrunberaud: Yop

10:10 dysfun: https://gist.github.com/jjl/d92dc6f7675cd23d0f1c870e72443f8f # finally finished my monster of a macro faking the state monad

10:13 justin_smith: dysfun: what about replacing (map #(symbol (str "r" %)) (range (count clauses))) with (repeatedly (count clauses) #(gensym "r"))

10:14 dysfun: ooh that would shorten it

10:15 justin_smith: also wouldn't break if the user had symbols like r0 in their form

10:15 ,(gensym "r")

10:15 clojurebot: r27

10:15 justin_smith: haha, well

10:15 dysfun: yes, though i considered it unlikely

10:16 and it makes it more annoying verifying the correctness for output :)

10:16 justin_smith: ,(= r28 (gensym "r"))

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

10:16 justin_smith: ergh

10:16 ,(= 'r28 (gensym "r"))

10:16 clojurebot: false

10:16 dysfun: and i just realised i can replace the (gensym "state") with `state#

10:16 justin_smith: that's a good one too

10:17 dysfun: okay, well it still appears to work :)

10:18 https://gist.github.com/jjl/d92dc6f7675cd23d0f1c870e72443f8f

10:18 (same gist)

10:18 justin_smith: 👍

10:19 dysfun: nice. apparently lxterminal doesn't like unicode

10:19 justin_smith: it was just a thumbs-up

10:19 dysfun: it's still long and ugly

10:21 justin_smith: dysfun: what about postgrey.squirrel.util/init - I would expect to see 123 instead of that

10:21 dysfun: aha yes

10:22 i was about to use it, so i'd have soon found that ;)

10:22 justin_smith: dysfun: I don't think there is any symbol to qualify in that form starting on line 21 - it's all values generated in the containing let, so you don't need ` there

10:22 though ~@ can be handy

10:22 dysfun: yes, i'm quoting precisely because of interpolation

10:23 it's like a sort of fucked up template language

10:23 justin_smith: haha

10:24 dysfun: okay, now interpolating the initial value as well

10:24 and all looks good enough for actually trying to use it

10:24 then again i said that a minute ago...

11:45 sdegutis: Why come this does not work,

11:46 ,(> (java.util.Date.) (java.util.Date.))

11:46 clojurebot: #error {\n :cause "java.util.Date cannot be cast to java.lang.Number"\n :via\n [{:type java.lang.ClassCastException\n :message "java.util.Date cannot be cast to java.lang.Number"\n :at [clojure.lang.Numbers gt "Numbers.java" 229]}]\n :trace\n [[clojure.lang.Numbers gt "Numbers.java" 229]\n [sandbox$eval25 invokeStatic "NO_SOURCE_FILE" 0]\n [sandbox$eval25 invoke "NO_SOURCE_FILE" -1]\n [cloj...

11:46 luma: > can only compare numbers

11:46 justin_smith: compare, on the other hand

11:47 ,(compare (java.util.Date.) (java.util.Date.))

11:47 clojurebot: 0

11:49 sdegutis: ,(->> #(compare (java.util.Date.) (java.util.Date.)) (repeatedly 100000) (distinct))

11:49 clojurebot: (0 -1)

11:49 sdegutis: haha clojure you so craaazay

11:49 So, you know about Ken M right?

11:49 justin_smith: of course

11:50 best idiot ever

11:50 sdegutis: It doesn't work so well on Reddit https://www.reddit.com/user/___kenm

11:51 They're too good of a target audience, they just downvote him, which hides his comments.

11:51 It only works on Yahoo News and Facebook because comments are listed there in chronological order.

11:52 I wonder if Datomic's < and > use (compare) internally.

12:02 ilevd: <offtop> Elm 0.17 is appeared http://elm-lang.org/blog/farewell-to-frp </offtop>

12:02 sdegutis: Why doesn't Clojure's > and < use compare internally?

12:02 ridcully_: ,(.before (java.util.Date. 0) (java.util.Date.))

12:02 clojurebot: true

12:02 sdegutis: Also <= and => that would make it nicer.

12:03 ridcully_: unfortunately there is no .beforeOrEqual, it just must be .before with the arguments reversed

12:03 justin_smith: sdegutis: the numeric method is faster

12:03 sdegutis: or (or (.before) (.equal))

12:03 justin_smith: now I understand this

12:06 ridcully_: ,(>= (.getTime (java.util.Date.)) (.getTime (java.util.Date.)))

12:06 clojurebot: true

12:16 OscarZ: is there something like (if-not-nil (myfunc xxx) default-value) which would evaluate to (myfunc xxx) if its not nil, and otherwise to default-value ?

12:17 luma: there's (or (my-func xxx) default-value, but that also evaluates to default-value if (myfunc xxx) is false (in addition to nil)

12:18 OscarZ: thanks luma, i think that works for me

12:18 justin_smith: OscarZ: also, there is fnil

12:18 ,((fnil inc 0) nil)

12:18 clojurebot: 1

12:18 justin_smith: ,((fnil inc 0) 2)

12:18 clojurebot: 3

12:21 OscarZ: justin_smith, yeah was looking at fnil but didnt understand it first.. now i do :)

12:27 justin_smith: OscarZ: the only difference from what you asked for is that it returns a new function, and you provide a default input, not a default result

12:28 OscarZ: so fnil identity would be what i want?

12:30 yes, seems to work

12:31 justin_smith: but or is more straightforward than (fnil identity default)

12:31 OscarZ: i was sure there was something like what i asked as "nil" seems to be pretty special value and often used like that... i guess "or" is very close though

12:56 sdegutis: justin_smith: wow another use for fnil

12:56 OscarZ: will myfunc ever return false?

12:59 I've not once used fnil in my code. It's usually overkill because false rarely turns up alongside nil.

12:59 Oh wait, no, we use fnil three times.

12:59 But every single time it's (fnil inc 0)

13:00 dysfun: fnil fnil fnil? is that like flatmap flatmap flatmap?

13:00 justin_smith: sdegutis: (fnil conj #{}) and (fnil conj []) are also very useful

13:00 sdegutis: justin_smith: hmm interesting

13:02 justin_smith: ,(reduce (fn [m [k v]] (update m k (fnil conj #{}) v)) {} '[[a 0][b 1][b 2][a 0][c 3]])

13:02 clojurebot: {a #{0}, b #{1 2}, c #{3}}

13:16 sdegutis: justin_smith: I wonder if reduce-kv can be used there

13:16 justin_smith: sdegutis: well, the input isn't a value hash-map

13:16 (and wasn't meant to be)

13:20 sdegutis: ok

13:27 Mustery solved:

13:27 Found in stack trace: java.util.Date/compareTo, clojure.lang.Util/compare, datomic.extensions/<

13:27 Hooray

13:29 dysfun: those bizarre errors sure do sell datomic to me

13:29 sdegutis: dysfun: no no that's me truncating the stack trace to show the lineage

13:30 dysfun: (cont'd) lineage which proves that < does in fact use clojure's compare function

13:31 well not technically, but basically

13:31 since clojure.core/compare uses clojure.lang.Util/compare internally

13:31 dysfun: you know, in several channels i hang out in, if you said "well not technically, but basically", someone would change the topic to quote you and embarrass you

13:33 justin_smith: sdegutis: datomic's < you mean

13:34 sdegutis: in my cont'd statment yes

13:34 dysfun: how is that embarrassing

13:34 i mean, yes, we all know technically correct is the best kind of correct

13:34 but basically correct is also acceptable often

13:35 dysfun: well it seems to me that this is quite clearly a falsificable fact, ergo they're the same thing

14:08 ben_vulpes: if anyone's looking for short-term contract work, i'd like a hand with a postback clojure app over the next 4 weeks. PM for details, introductions happily accepted. local to portland would make me giddy, although possible to work around.

15:31 {blake}: You know, I had it in my head that that one was going to happen in 2016 or 2017. Couldn't figure out why I hadn't heard anything abou it.

15:31 kwladyka: anybody with good emacs experience and Intellij Idea + Cursive can say something clever? :) I consider to learn emacs, because it is like religion.... society demand it in some way, it determine how others see you :) If you use emacs you are pro :) Bla bla... back to my question, somebody use both and can say something in topic?

15:31 ridcully_: you might have confused 2017 with 2037

15:31 or some windows version goes boom soon

15:31 marcy--: can someone tell me how to get a clojure repl up with a dependency without relying on lein/boot? calling `require` after `java -cp "clojure.jar:dependency.jar" clojure.main` is not working.

15:31 {blake}: ridcully: Yeah, might be. There's some kind of twist on the Mayan-end-of-the-world thing that falls on 2017, too.

15:32 justin_smith: marcy--: that works, if all your deps are in that cp

15:32 marcy--: for example, you probably want the directory with your source-files to be in that cp arg

15:32 eg java -cp clojure.jar:src:dependency.jar clojure.main

15:32 the "" is not needed

15:33 (unless your deps paths have wierd names, of course)

15:33 engblom: kwladyka: I am in the minority as I do not use Emacs for programming. I have many times been giving it a chance and it is very decent for developing programs in any Lisp dialect. Personally I am using the "rivalling" editor which is called vim.

15:34 kwladyka: Regardless if you go with emacs or vim (both are getting the task done), you will have to experience a steep learning curve that will pay off later

15:40 justin_smith: require only works with an ns form, otherwise (load-file ...) will handle anything you throw at it

15:40 anything that would work in a repl, of course

15:41 one could also nitpick about *file* not being bound, and that thing that makes gen-class work...

15:42 dysfun: yeah, so it's actually not all that clear cut

Logging service provided by n01se.net