#clojure log - Jan 18 2016

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

0:55 Quezion: Is there a way to use a defined multi-arity function to satisfy a multi-arity protocol implementation?

0:55 e.g. instead of wrapping color-rgb, directly use the defined function to fulfill the protocol. http://pastebin.com/cN4zD9nw

0:56 rhg135: ,(doc extend)

0:56 clojurebot: "([atype & proto+mmaps]); Implementations of protocol methods can be provided using the extend construct: (extend AType AProtocol {:foo an-existing-fn :bar (fn [a b] ...) :baz (fn ([a]...) ([a b] ...)...)} BProtocol {...} ...) extend takes a type/class (or interface, see below), and one or more protocol + method map pairs. It will extend the polymorphism of the protocol's methods to call the suppl...

0:56 rhg135: I think it'll work, but I've never tried

0:57 justin_smith: using extend loses the dispatch efficiency that comes with protocols though

0:57 rhg135: one of the examples there uses multi arities, yeah

0:57 Quezion: Looks like extend isn't implemented in CLJS, but I'll see if I can find a workaround. TY

0:57 rhg135: well, it's the only way it could work, justin_smith, inline would be madness

0:58 justin_smith: right, just saying that since it can't be inline it has that disadvantage

0:58 rhg135: then you'd have to eval in the macro

1:02 vrdhn: hi. a cider/company mode question: f1 in company-complete says 'no documentation available' ; how to get doc ?

1:03 rhg135: NaN strikes again... NaN% of battery

1:08 vrdhn: lein search is just stuck at downloading nexus-maven-repository-index.properties !!

2:22 amalloy: rhg135: you shouldn''t have bought a batery with 0 capacity!

2:23 rhg135: I assure you it had 106 right before

6:16 lxsameer: I'm looking for a good book to read on distributed programming topic, any suggestion ?

6:23 owlbird: anyone has used Cursive for clojure editing ? https://cursive-ide.com/

6:24 Does it support segment compiling like C-c C-c in emacs ?

6:25 scottj: owlbird: clarify: segment = file, region, top-level expression?

6:25 owlbird: region

6:26 by using emacs with cider, I could C-c C-c to compile a region, or C-c C-k to compile the whole file. don't know how to do it in cursive

6:27 I'm trying to persuade a group of java programmer to have a try with clojure, they were familiar with intelliJ, so...

6:28 scottj: owlbird: did you look through the keybindings dialog?

7:45 owlbird: scottj: IntelliJ has no suitable operation for a region compilation

7:46 beaky: hello

7:46 are there alternative ways to use a database in postgres besides clojure.jdbc

7:46 in clojure*

7:47 i wanna be able to invoke stored procedures and stuff

8:26 neoncontrails: ,(map #(assoc-in {:a false :b false :c false} [%] true) [:b :a])

8:26 clojurebot: ({:a false, :b true, :c false} {:a true, :b false, :c false})

8:27 neoncontrails: How to edit this function so it returns {:a true :b true :c false})?

8:34 ridcully_: ,(reduce (fn [m k] (assoc m k true)) {:a false :b false :c false} [:a :b])

8:34 clojurebot: {:a true, :b true, :c false}

8:35 neoncontrails: ridcully_: that's the ticket. thank you!

8:44 beaky: hello

8:44 how do i build a rest api with clojure

8:45 ridcully_: beaky: have you looked on some of the options there? http://www.clojure-toolbox.com/

8:46 Ricardo-Arges: There's also a brief write up on options on the JUXT technology radar.

8:47 beaky: wow so many options

8:47 whats juxt

8:47 ridcully_: the function or the company?

8:49 beaky: thought it was a technology

8:49 https://juxt.pro/radar.html oh this one

8:49 ridcully_: beaky: missing there: kekkonen. and i'd add catacumba also to the restfull stuff, since there is handler for it

8:52 Ricardo-Arges: Plus, fwiw, JUXT mentions that "Pedestal [or compojure/ring] may be easier" than Liberator. I've yet to find a case where Pedestal is easier than any of the smaller alternatives. That may come from the fact that they already had adopted it.

8:53 mpenet: well, radar stuff is highly subjective

8:54 Ricardo-Arges: @mpenet Certainly.

9:04 wink: https://twitter.com/bodil/status/597766837548507136 :P

9:05 I still like reading them, if not for discovering new things

9:07 oracle123: I want to use rabbitmq to do task on multiple hosts, and also want to use core.aysnc. What's the best solution for core.async+rabbitmq? I saw there is a lib kehaar on github, is it the one I should go?

9:12 mpenet: wink: :] sure it's entertaining, and you might discover interesting libs. I guess the tone is the real controversial part.

9:12 beaky: i love sql

9:20 wow

9:21 https://github.com/friemen/aggregate this is a life saver

9:21 how have i been doing sql with clojure without knowing about this lib

9:25 i love clojure

9:25 most clojure libs are so tiny even i can read and understand what they really do

9:25 just like nodejs

12:24 irctc: Hello, these may be a dumb question or already answered somewhere, but what (if any) would be the path to look down if one wanted to add syntax for clojure? for example, if i wanted "!(false)" to return true *not that i want this, just example*, or (/re.ex/ "regexs are cool") to expand to ((partial re-find #"re.ex") "regexes are cool")? any resources to look into are appreciated (or just letting me know if not easily possible)

12:24 justin_smith: irctc: for things like that you would need to fork clojure itself, and change the java code that implements the parser

12:27 irctc: @justin_smith: roger that, kinda a bummer but thanks for letting me know. i think regexes somewhat like that would be somewhat slick, like how you can use (:a {:a 1 :b 2}) or (map :a list-of-maps), it would be nice to do with regexes on strings maybe, but oh well, i just thought would be neat, i havent ran into the specific need for it yet or anything

12:38 ridcully_: justin_smith: i followed your example and uberward me some clj-http, specter, puget and a little state for url/request defaults

12:39 justin_smith: ridcully_: cool, how did that work out?

12:39 ridcully_: using it to handle elasticsearch api right now. super sweet

12:40 yazirian: irctc: there is limited reader extensibility with e.g. tagged literals http://clojure.org/reference/reader#_tagged_literals

12:40 without getting into whether it is recommended or not to do that :)

12:43 irctc: yazirian: thank you, ill check it out, and roger that on it being potentially the non-reccomended way of doing things

12:58 mpenet: irctc: dunno what's the context for you, but if you have to create a mini lang that compiles to clojure instaparse is a good starting point

12:59 I had to do this recently to create a bastard child of lucene-like & sql like language and it took hours

12:59 luxbock: irctc: you could do what you suggest with regexes if IFn were a protocol like it is in CLJS

12:59 but it's not :P

13:57 irctc: mpenet:, luxbock: thank you for the leads, looks like someone had a similar idea (and actually did it) in cljs using the IFn thing. https://gist.github.com/alandipert/2346460

15:26 benjyz1: hi. I'm trying to understand agents. I've read several explanations, but still don't quite get it. what is a typical example?

15:41 jjttjj: benjyz1: I remember the explanation in the book Clojure Programming made agents click for me, seems like you can get a pretty big exerpt from it here: https://www.safaribooksonline.com/library/view/clojure-programming/9781449310387/ch04s10.html I particularly liked the web crawler example at the end

15:43 benjyz1: yes, I'm reading it

15:43 "The one we’ll build here will be extraordinarily basic,34 but it will demonstrate how agents can be used to orchestrate and parallelize potentially very complicated workloads."

16:07 sdegutis: Hey you all.

16:07 How is this going?

16:16 gfredericks: has anybody tried to make a datomic-like lazy-map API on top of a relational database?

16:16 (accepting the obvious downsides w.r.t. caching that datomic doesn't have)

16:18 I'm just thinking again about the problem of having a database-exploration experience that remotely approaches ActiveRecord

16:18 even if it isn't clean enough for production code

16:19 (removing production as a target use case frees up a lot of magical tactics to get succinctness)

16:21 hiredman: gfredericks: you are saying it would return a map that would automatically and lazily follow fk relationships?

16:22 korma's database stuff may have done something like that

16:22 sdegutis: gfredericks: that sounds epic

16:23 gfredericks: what your describing reminds me of ActiveRecord tho

16:25 gfredericks: sdegutis: I mentioned ActiveRecord as the inspiration so that's not surprising

16:25 hiredman: yeah that sort of thing is the main idea

16:26 TEttinger: gfredericks: you did some intensive research into JVM PRNGs, right?

16:26 gfredericks: TEttinger: FSVO intensive

16:27 TEttinger: I was shocked by how slow j.u.Random is

16:27 gfredericks: I think it has extra slowdown because it wants to be threadsafe

16:27 IIRC

16:28 TEttinger: ahhh

16:28 gfredericks: whereas j.u.SplittableRandom removes that and the docs say "don't share this between threads you dummy"

16:28 I think it amounted to something like a 5x slowdown

16:28 TEttinger: that would explain it, I was wondering how an LCG takes roughly 9.8x as much time as a... whatever splitmix64 is. the one SplittableRandom uses

16:28 https://github.com/SquidPony/SquidLib/blob/master/squidlib-performance/src/main/java/squidpony/performance/RNGBenchmark.java#L53-L67

16:29 JMH is weird for benchmarking java

16:29 I have some freaky results in there, things that wrap another class being faster than the class they wrap

16:30 RNGBenchmark.measureRandom and RNGBenchmark.measureRandomInt use j.u.Random, the first makes a billion longs, the second a billion ints

16:32 the weird results are on the other RNG algos, especially when wrapped in the extra-features-slightly-slower-maybe 'R' suffixed variants

16:33 LightRNG there is SplitMix64, Permuted is PCG-Random (RXS M XS -- random xorshift, mcg multiply, fixed xorshift variant)

16:34 I might be doing something wrong on the permuted

16:34 neoncontrails: Funny y'all mention Korma. I came across it a few hours ago, it looks charmingly user-friendly

16:36 sdegutis: gfredericks: hmm I musta missedit

16:40 neoncontrails: Speaking of Korma. Can I bounce a question off you database experts?

16:40 What's the preferred datatype to store lists?

16:41 I see SQL doesn't have lists, which makes sense. That would have to be constructed in memory after all

16:42 But if you're ultimately converting the values back to lists, is there an obvious best choice for the data type? I'm leaning JSON

16:46 sdegutis: neoncontrails: I use lists in Datomic.

16:48 neoncontrails: sdegutis: I'm almost certainly going to look into Datomic the next time I make a db app

16:48 sdegutis: Cool beans.

16:51 neoncontrails: jdbc works, but the documentation is a bit thin. Hard to figure out what I can do vs. what's optimal, particularly from the Clojure vantage point

16:51 Seems like Datomic is a bit more... Clojurey

17:16 sdegutis: jdbc is great

17:20 gfredericks: TEttinger3: yeah benchmarking that stuff can drive you crazy

17:21 if you want to fully go crazy, try also testing for randomness quality

17:33 kenrestivo: how does one actually do that? come to think of it, who determines that a CSRNG is actually strong enough?

17:35 p_l: kenrestivo: long testing and looking for biases

17:38 gfredericks: lots of stats

17:39 kenrestivo: https://en.wikipedia.org/wiki/Diehard_tests

17:41 kenrestivo: cool, thanks, fascinating

18:10 rhg135: is there a way to use a map with reify to implement a protocol ala extend?

18:27 justin_smith: rhg135: sure, but it might be easier to just use defrecord

18:29 rhg135: I guess, I wanted to let users implement a protocol without having it available, but thats not a good idea anyway

18:30 justin_smith: so you were trying to hide the protocol?

18:36 rhg135: in essence

19:30 WickedShell: How do you type hint passing an array (such as an array of strings) (IE I'm trying to call this FN https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/SelectBox.html#setItems-com.badlogic.gdx.utils.Array- )

19:39 gfredericks: something like ^"[String" I think

19:40 WickedShell: ohhhh qoutes! I never thought of adding the qoutes :D

19:41 justin_smith: gfredericks: that with a semicolon I think?

19:41 ,(class (into-array ["a"]))

19:41 clojurebot: [Ljava.lang.String;

19:41 justin_smith: so yeah, it needs an L, the java.lang part may be optional, and it needs a semicolon

19:43 WickedShell: and it needs the qoutes I'm assuming so that the [ doesn't run off?

19:44 justin_smith: so that the reader doesn't barf on it basically

19:44 WickedShell: yeah

19:45 gfredericks: ~I dunno it |could be| anything

19:45 clojurebot: Roger.

19:45 gfredericks: ~there's no way |to| tell

19:45 clojurebot: c'est bon!

Logging service provided by n01se.net