#clojure log - May 09 2015

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

0:52 TEttinger: Niac: you still around?

0:54 ,(java.awt.Toolkit/getDefaultToolkit)

0:54 clojurebot: #error{:cause "denied", :via [{:type java.lang.ExceptionInInitializerError, :message nil, :at [java.lang.Class forName0 "Class.java" -2]} {:type java.lang.SecurityException, :message "denied", :at [clojurebot.sandbox$enable_security_manager$fn__839 invoke "sandbox.clj" 69]}], :trace [[clojurebot.sandbox$enable_security_manager$fn__839 invoke "sandbox.clj" 69] [clojurebot.sandbox.proxy$java.lang.Se...

1:57 Niac: can anybody tell me how to use Graphic in clojure

3:08 expez: If I have a protocol, how can I get at the generated java interface?

3:09 (:on-interface AProtocol) returns what looks like a classname, but findClass throws an exception when I try to use it.

3:16 heh, doing (compile 'my.ns) generated the interface

3:24 kaffeeboehnchen: What is the easiest way to find doubles in a lists? For example I have (1 2 1 4) and want the 1.

3:25 tatut: perhaps frequencies

3:26 kaffeeboehnchen: Thanks, I'll try it out!

3:28 (first (keys (frequencies list))) works :)

3:59 ok, not always

4:09 TEttinger: kaffeeboehnchen: do you want specifically doubles?

4:10 ,(def one-or-two [1 2 1 4 3 3 5 7])

4:10 clojurebot: #'sandbox/one-or-two

4:12 TEttinger: ,(defn appearing-twice [coll] (map first (filter (fn [[_ v]] (= v 2)) (frequencies coll))))

4:12 clojurebot: #'sandbox/appearing-twice

4:12 TEttinger: ,(appearing-twice one-or-two)

4:12 clojurebot: (1 3)

4:14 TEttinger: if you want appearing more than once, specifically...

4:14 ,(defn appears-multiple [coll] (map first (filter (fn [[_ v]] (> v 1)) (frequencies coll))))

4:14 clojurebot: #'sandbox/appears-multiple

4:15 TEttinger: ,(def crazy-mix [1 2 1 4 3 3 3 5 7 7 7 7 7 7 9])

4:15 clojurebot: #'sandbox/crazy-mix

4:15 TEttinger: ,(appears-multiple crazy-mix)

4:15 clojurebot: (1 3 7)

4:15 kaffeeboehnchen: TEttinger: Very cool, thanks!

4:16 TEttinger: hope it helps!

4:16 frequencies is great

4:23 kaffeeboehnchen: TEttinger: What does [[_ v]] do?

4:23 TEttinger: destructures the pair, binds the key to _ (which is commonly used as a name for unused variables) and the value to v

4:23 kaffeeboehnchen: Ok, cool!

4:24 (clojure beginner here)

4:24 TEttinger: ,(map (fn [[_ v]] (+ v 1)) {:a 1, :b 2, :c 4})

4:24 clojurebot: (2 3 5)

4:25 TEttinger: or the other way around...

4:25 ,(map (fn [[k v]] (str k)) {:a 1, :b 2, :c 4})

4:25 clojurebot: (":a" ":b" ":c")

4:25 TEttinger: and more importantly...

4:25 ,(map (fn [[k v]] [v k]) {:a 1, :b 2, :c 4})

4:25 clojurebot: ([1 :a] [2 :b] [4 :c])

4:27 TEttinger: that format, of a sequence of pairs, can be converted into a hashmap easily. which is important, because most fns that operate on collections in clojure return seqs (same thing as lists) or lazyseqs (which are a bit more complicated), and if given a map will treat it as a seq of pairs

4:28 ,(into {} (map (fn [[k v]] [v k]) {:a 1, :b 2, :c 4}) )

4:28 clojurebot: {1 :a, 2 :b, 4 :c}

4:29 Niac: import java.awt.*;

4:30 how to write in repl

4:30 ARM9: I'm stumped http://benchmarksgame.alioth.debian.org/u64q/program.php?test=pidigits&lang=clojure&id=5

4:33 TEttinger: Niac: clojure does not have any import all thing. you can... (not sure if this bot can do it)

4:34 ,(import 'java.math.MathContext)

4:34 clojurebot: java.math.MathContext

4:34 TEttinger: ,(MathContext. 1000)

4:34 clojurebot: #object[java.math.MathContext 0x851984b "precision=1000 roundingMode=HALF_UP"]

5:05 wasamasa: what was the website again that did visualize the relations between libraries from clojars again?

5:10 ah, found it: https://crossclj.info/

5:13 kaffeeboehnchen: don't overdo destructuring though

5:14 kaffeeboehnchen: wasamasa: I'll keep it in mind. :)

6:00 Niac: quit

6:00 exit

6:03 hellofunk: expel

7:02 TEttinger: Raynes: did you change the refheap API recently?

7:06 expez: Given a name as a string, how can I get at the protocol by that name?

7:18 Glenjamin: Yo, could anyone recommend a good place to ask about microservice deployment? (i know a bunch of people here are using such approaches)

7:19 Specifically, i'm wondering if it's worth having a separate unix user per service deployed

7:36 tahmid: I have a silly question

7:36 How to switch the value of an atom from true to false

7:36 I need to write something like (swap! myatom func)

7:36 what should be the func

7:36 oddcully: ,(doc reset!)

7:37 clojurebot: "([atom newval]); Sets the value of atom to newval without regard for the current value. Returns newval."

7:37 tahmid: Thanks

7:38 scottj: tahmid: if it's false do you want it to be true? (swap! myatom not)

7:38 tahmid: yes

7:39 Nice trick

7:41 escherize: Cheap hostels are kind of sketchy

8:25 TEttinger: $mail Raynes can you $mail me any information about API changes to refheap? I've been getting "failed to paste: peer not authenticated"

8:25 lazybot: Message saved.

8:36 nicferrier: is there a pattern list for core async anywhere?

8:36 I do really enjoy working with it... but somtimes get tied in knots wondering how to sync things.

8:37 I'm writing a udp repeater right now... and I can't work out whether I need to write a message loop around the udp receive or somehow lift the udp receive

9:44 anti-freeze: Hi everyone, what would be the best way to execute a file transfer in a different thread. I don't care about returns or shared state. Would I just use a future or dosync?

9:45 Actually, the operation will never be dereferenced. So if I use a future, i'll never be using @(transfer-file ,,,)

9:46 So an asynchronous, uncoordinated operation

9:47 But it has side effects

9:48 Glenjamin: probably future or thread

9:48 (doc thread)

9:48 clojurebot: Pardon?

9:48 Glenjamin: hrm

9:48 i could have sworn that existed

9:49 tatut: it's in core.async

9:49 anti-freeze: Yea, I can't find (doc thread) either

9:49 Ah right. So, a future then?

9:49 Glenjamin: future for naive stuff, but be aware you might want a pool/queue if you're doing this a lot

9:50 anti-freeze: Glenjamin: Not really, just profile picture uploads. Futures run in native threads right?

9:50 Glenjamin: yes, but provide no control over how many run at once

9:51 anti-freeze: Glenjamin: Well, I guess not

9:51 Also, is it cool to log stuff from that future?

9:51 tatut: but I'd suggest caring about the result of the execution :)

9:51 Glenjamin: something like core.async can help there, but (future) is fine for now

9:52 tatut: so the core.async thread is good because it returns a channel from which you can receive the result

9:53 anti-freeze: tatut: Currently I don't really care about the result, because I don't have any error checking. What happens if it throws an exception though? Does it get caught in the instantiating thread?

9:54 Glenjamin: it's captured in the future

9:54 tatut: but if you never deref it, you will not know about it

9:54 Glenjamin: ,(future (throw (Exception. "abc")))

9:54 clojurebot: #error{:cause "no threads please", :via [{:type java.lang.SecurityException, :message "no threads please", :at [clojurebot.sandbox$enable_security_manager$fn__857 invoke "sandbox.clj" 94]}], :trace [[clojurebot.sandbox$enable_security_manager$fn__857 invoke "sandbox.clj" 94] [clojurebot.sandbox.proxy$java.lang.SecurityManager$Door$f500ea40 checkAccess nil -1] [java.lang.ThreadGroup checkAccess "Th...

9:54 Glenjamin: $(future (throw (Exception. "abc")))

9:55 anyway, the deref will re-throw, i'd suggest poking around your repl a bit :)

9:55 anti-freeze: Alright, thanks guys

9:56 By the way, agents aren't really what I want right?

9:57 Confusionist: Is this a correct core.typed signature: (ann foo (Fn [Any -> String] [Any Any -> String])) ?

9:58 On the line where foo is subsequently declared, I get First argument to TApp must be TFn, actual: clojure.lang.Fn

9:58 anti-freeze: Also, seems like it doesn't work with futures, only with dosync.

9:58 Because I'm never dereferencing the future

9:58 I think?

10:00 om: how do you add deps to the classpath dynamically in the boot repl?

10:01 at the moment, I set-env! the deps and run the aot task on the namespace

10:01 does it sound like standard practice?

10:01 Confusionist: Hmmm... cf returns an IFn in the signature

10:04 anti-freeze: Just do be clear, dosync executes stuff in a different thread right?

10:05 hyPiRion: anti-freeze: no

10:06 anti-freeze: hyPiRion: So, I have to use futures then I guess

10:09 hyPiRion: anti-freeze: I'd use that to start out with.

10:31 supersym: Is it ok/possible to add new methods to a protocol definition (meaning extend-protocol but with their virtual methods, not the concrete realizations)?

10:33 Confusionist: If I (load) a file that declares an existing (ns) at the top, I get errors from core.typed because of rebinding of existing vars. If I use (in-ns), there is no problem. But shouldn't (ns) be usable wherever (in-ns) could be used?

10:41 supersym: Confusionist: no... in-ns doesnt try to make a ns symbol, ns does

10:41 justin_smith: supersym: that's wrong - in-ns will create an ns if it does not exist

10:41 clojurebot: I don't understand.

10:42 supersym: oh ... you are right

10:42 my bad (memory)

10:43 justin_smith: after running in-ns and creating an ns, one will usually want to run (clojure.core/refer-clojure)

10:43 if only so you can then access in-ns again to get back into the right ns :)

10:44 dnolen: supersym: not aware that anything like that is possible wrt protocols

10:44 Confusionist: So in one case I (load "file"), where file contains (ns app.core). In the other case it contains (in-ns 'app.core). The first results in errors, the second doesn't

10:44 supersym: dnolen: thanks

10:45 Confusionist: And the file in which I (load "file") starts with (ns app.core) in which it requires clojure core.typed.

10:45 That's all of the code. Should ns and in-ns behave differently in this way?

10:46 supersym: Ive only seen cases of in-ns used that way, that is not to say, the other method shouldn't work

10:46 that is, in conjunction with load

10:56 dnolen: cfleming: btw, find symbol seems to not work so well for symbols in .cljc files

11:00 supersym: oh I see I don't really have to.. defrecord supports multiple specs so I can stack new ones in their own protocol, figures.

11:54 n8dawg: hi all, had a core.async question, if I have an input and output channel, is there an easy way to 'glue' them together into one channel?

11:55 kaiyin: Is there an alternative for (Class/forName "[[D")? This is causing some error in cursive.

12:01 puredanger: n8dawg: see pipe

12:02 hyPiRion: uh

12:02 ,(subseq (into (sorted-set) (range 5 10)) <= 0 <= 100)

12:02 clojurebot: (6 7 8 9)

12:02 hyPiRion: shouldn't that one actually return (5 6 7 8 9) ?

12:04 nvm, it should be (... >= 0 <= 100).

12:09 jsnikeris: Hi all, core.async question: I just discovered that the parking operations must be (lexically?) enclosed within a go block. I guess this is what the documentation means when it says "any visible calls". Doesn't this tie your hands a bit with respect to abstracting parts of your process into functions? I'm writing a process with many steps, and in some steps I need to take input from a channel to make a decision. I've abstracted the

12:09 steps into functions so it's easier to understand. However, it seems like I'm not going to able to park in those steps. It seems suspect for me to go with the blocking operations simply because my process has many steps that I've broken out into functions.

12:12 n8dawg: puredanger: its not quite pipe i'm after. I'll paste some code

12:12 (deftype CompositeChannel [^impl/WritePort input ^impl/ReadPort output] impl/WritePort (put! [this val handler] (put! input val handler)) impl/ReadPort (take! [this handler] (take! output handler)) impl/Channel (closed? [_] (closed? input)) (close! [this] (close! input)))

12:13 puredanger: basically i want writes to go to an input channel, and reads to come from an output channel

12:34 hellofunk: n8dawg: please use something like refheap or github gist to share code rather than pasting into the chat window

12:59 brainproxy: jsnikeris: you can wrap the body of each function definition in a go block

13:00 but the bigger picture is that "go-ing async" is a decision which tends to ooze through other parts of your code base

13:01 that being said, remember that the double-bang variants don't have to be used in a go block

13:01 but they will truly block the thread in which they're used

13:43 tahmid: I can’t get figwheel to work

13:43 Here’s my project.clj

13:43 http://pastebin.com/6EPJcXzR

13:44 And I am getting this error java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number

13:51 Issue is solved

13:51 :server-port should have been a number , not a string

13:52 Thanks to justin_smith for pointing that out

13:52 (+ 2 justin_smith)

14:20 kaiyin: ,(condp some [1 2 3 4] #{0 6 7} :>> inc #{4 5 9} :>> dec #{1 2 3} :>> #(+ % 3))

14:20 clojurebot: 3

14:20 kaiyin: why does this return 3?

14:21 I would expect 2.

14:21 justin_smith: (some #{4 5 9} [1 2 3]) -> 4 -> dec -> 3

14:22 err, I meant [1 2 3 4] of course

14:23 kaiyin: justin_smith: ah, i thought it was (some [1 2 3 4] #{4 5 9}). ok, got it.

14:24 justin_smith: ,(some [1 2 3 4] #{4 5 9})

14:24 clojurebot: #error{:cause nil, :via [{:type java.lang.IndexOutOfBoundsException, :message nil, :at [clojure.lang.PersistentVector arrayFor "PersistentVector.java" 153]}], :trace [[clojure.lang.PersistentVector arrayFor "PersistentVector.java" 153] [clojure.lang.PersistentVector nth "PersistentVector.java" 157] [clojure.lang.APersistentVector invoke "APersistentVector.java" 283] [clojure.core$some invoke "core...

14:25 justin_smith: ,(some #{4 5 9} [1 2 3 4])

14:25 clojurebot: 4

14:38 Viesti: mmh

14:40 was baffled by a clojure.tools.namespace.repl/refresh + http-kit handler reload problem for a while

14:40 justin_smith: what was the issue?

14:41 Viesti: had (run-server #'handler ...) and refresh didn't reflect changes until using (disable-unload!) in the namespace

14:42 I guess the thing is that refresh unloads the whole namespace, recreates it and so (run-server ...) ends up holding some old var

14:42 ring reload middleware tracks changed namespaces and does (require :reload)

14:42 justin_smith: yeah, dereferencing the old var would give you the old contents

14:43 Viesti: yep

14:43 justin_smith: if the whole namespace is created from scratch

14:43 Viesti: just feeling a bit stupid now :P

14:43 anyways, saying it out loud cleared by thoughts :)

14:44 a good refreshment for me on how vars and reloading work

14:46 was actually trying to do this in a code camp event, goal being to keep the server alive and still be able to reload at will but not on every request like ring reload middleware :)

14:57 justin_smith: Viesti: another option would be putting the server in a component, and running (stop) (refresh) (start)

14:58 then you don't need to provide the var either

14:58 Confusion: Viesti, you've seen this: http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded?

14:59 If not, there may be something useful in there

14:59 tahmid: ,(vec [[1] [2] [3]])

14:59 clojurebot: [[1] [2] [3]]

14:59 Viesti: yep, read that, using https://github.com/weavejester/reloaded.repl in another project

14:59 the thing was that I didn't want to stop the server while reloading

15:00 I'd normally make a server component so that on Licecycle/stop it actually gets stopped

15:02 in the component case a new system would get created in the reload cycle, old one discarded

15:03 in this case I wanted to keep the server around, just pass new code for the hander :)

15:03 but still be able to reload namespaces in dependency order

15:04 tahmid: I have this vector [[1] [2] [3]]

15:05 How can I turn it into this [1] [2] [3]

15:06 Confusion: Viesti, understood. Stopping and reloading is easy :)

15:08 Viesti: tahmid: are you looking for something like this? http://stackoverflow.com/questions/5232350/clojure-semi-flattening-a-nested-sequence

15:09 Confusion: tahmid, what are you subsequently going to do with those 3 vectors?

15:09 tahmid: put them inside a hiccup div

15:10 [:div (for [x vec-of-elements] x)] -> this gives me a list of individual vectors

15:11 seangrove: Ah, in dependencies hell. Datomic-free works, but datomic-pro pulls in aws-sdk, which relies on some old version of fasterxml/jackson/whatever, which causes all kinds of overriding, and then finally blows up with a java.lang.NoSuchMethodError

15:13 Confusion: tahmid, push the :div into the vec using something like (vec (cons :div [[1] [2] [3]]))?

15:14 Viesti: seangrove: maybe :exclusions for the jackson stuff on datomic-pro might help?

15:16 seangrove: Viesti: Added a bunch of exclusions elsewhere, and then added in explicit dependencies on the jackson stuff, seems like a bit of progress

15:16 Viesti: hum, maybe this could also work (let [xs [[1] [2]]] `[:div ~@xs])

15:16 Confusion: ,(into [:div] [[1] [2] [3]))

15:16 clojurebot: #<RuntimeException java.lang.RuntimeException: Unmatched delimiter: )>

15:16 Viesti: seangrove: hope it works :)

15:16 Confusion: ,(into [:div] [[1] [2] [3]])

15:17 clojurebot: [:div [1] [2] [3]]

15:23 tahmid: [:div (for [x vec-of-elements] x)] this worked

15:24 :viesti :Confusion Sorry I got disconnected from the net

15:26 Viesti: tahmid: Confusion mentioned this: (into [:div] [[1] [2] [3]])

15:26 ,(into [:div] [[1] [2] [3]])

15:26 clojurebot: [:div [1] [2] [3]]

15:27 Viesti: probably better than the idea that I had

15:27 tahmid: Viesti: I was looking for something like that, You guys are so awesome

15:27 Viesti: ,(let [xs [[1] [2]]] `[:div ~@xs])

15:27 clojurebot: [:div [1] [2]]

15:27 Viesti: thanks :)

16:44 jsnikeris: brainproxy: So basically make each function a process. Yeah, I'm not sure if that makes sense in my case, but I'll have to mull it over. And yes, I'm currently using the double bang variants.

16:58 kaiyin: These two are the same, right? (condp = i 0 1 1 0) (case i 0 1 1 0)

17:00 turbofail: they don't have identical performance

17:05 gfredericks: ,(with-redefs [= not=] (let [i 1] (condp = i 0 1 1 0)))

17:05 clojurebot: 1

17:06 gfredericks: ,(with-redefs [= not=] (let [i 1] (case i 0 1 1 0)))

17:06 clojurebot: 0

17:31 kaiyin: gfredericks: that was a clever hack. :)

17:32 From the clojure programming book: In the long term, interfaces for core abstractions are planned to be replaced by protocols

17:32 Is this done in 1.7?

17:32 puredanger: no

17:33 kaiyin: ok. how come it's already done in clojurescript?

17:33 puredanger: because clojurescript had the benefit of hindsight

17:33 kaiyin: ok

17:34 puredanger: protocols didn't exist till several years into Clojure (but before the ClojureScript impl was written)

17:36 gfredericks: puredanger: has there not been any moves in that direction because "it's a lot of work" or backwards compatibility concerns?

17:36 just curious

17:37 puredanger: well it's definitely a lot of work :)

17:37 and likely very hard to make backward compatible

17:38 and would likely be slower

17:38 gfredericks: oh right

17:38 puredanger: and users wouldn't gain many benefits

17:38 Glenjamin: that's one of the dunaj things iirc

17:38 gfredericks: so it's fine in cljs because js doesn't have a core interface concept anyhow

17:39 kaiyin: clojurebot: dunaj

17:39 clojurebot: Pardon?

17:39 Glenjamin: $google dunaj

17:39 lazybot: [Dunaj - Wikipedia, the free encyclopedia] http://en.wikipedia.org/wiki/Dunaj

17:39 Glenjamin: oh, probably not that

17:39 gfredericks: puredanger: the perf point is interesting because that might potentially mean that even with hindsight you'd choose not to use protocols on the jvm?

17:39 Glenjamin: http://www.dunaj.org/

17:40 puredanger: gfredericks: hard to say. lotta variables.

17:40 there are a number of places where we have hard-coded conditional logic (lot of RT methods)

17:41 that stuff sucks and is really fragile for inlining

17:41 but could potentially be faster with protocol style invocation

17:41 gfredericks: oh and those places could conceivably speed up with protocols you mean?

17:41 jinx

17:41 puredanger: *maybe*

17:41 it would be a lot of work to find out :)

17:42 gfredericks: roger

17:42 puredanger: I'm not really running towards something that is a huge amount of work, breaks people's stuff, and *might* be faster (but also might be slower), but may have no other visible benefits to existing users

17:43 gfredericks: if not for those reasons, do it because people occasionally suggest it from time to time

17:43 puredanger: yes, good point

17:43 Glenjamin: it would probably make custom datatypes a bit easier

17:44 especially in cljc scenarios

17:44 puredanger: you'd be extending protocols instead of extending interfaces

17:44 doesn't seem like it'd be much different

17:44 could be more portable for sure

17:44 Glenjamin: i seem to recall i've seen some areas where you can't hook in due to lack of protocol, but i can't bring any to mind right now

17:45 might have been existing types

17:45 someone was around a few weeks ago struggling to port something from cljs to clj

17:46 ah yes, he was porting datascript

17:54 andyf: So grateful that I had no drinks passing through my mouth or throat when gfredericks made his last comment, or said drinks would have exited my body painfully

17:55 gfredericks: phew

18:52 kaiyin: is it true that every java interface can be translated into a deftype equivalently?

18:52 justin_smith: kaiyin: you can make a deftype that instantiates any interface you like, if that's what you mean

18:52 but they are two different kinds of things

18:56 kaiyin: ok

18:58 the way deftype behaves is very much like java.

18:59 justin_smith: it's true, it's like defining a java class that can only implement methods that alreayd exist in some interface

19:01 kaiyin: is there a way to mix java and clojure code? i mean MyClass.java directly, not through a jar file.

19:01 justin_smith: the clojure compiler does not use javac

19:01 kaiyin: so the answer is no.

19:01 justin_smith: so, not really, without a big hack of some sort that would involve calling javac via a shell command I guess

19:02 kaiyin: ok, i see. that's probably why we have deftype.

19:02 justin_smith: there is also gen-class

19:08 andyf: also definterface

21:00 bostonaholic: I'm creating a new clojure newsletter. Email me at clojure@airshiplabs.com for the latest news and tips on Clojure.

21:10 Steve_Miller: Probably easy for most here, but is there an easier way?

21:10 (def mymap {"company" {:value "something"} "accountNumber" {:value "store"}})

21:10 (reduce #(merge %1 %2)

21:10 (map #(hash-map (keyword (key %)) (:value (val %))) mymap))

21:12 gfredericks: ,(def mymap {"company" {:value "something"} "accountNumber" {:value "store"}})

21:12 clojurebot: #'sandbox/mymap

21:12 gfredericks: ,(into {} (for [[k {v :value}] mymap] [(keyword k) v]))

21:13 clojurebot: {:company "something", :accountNumber "store"}

21:14 Steve_Miller: thanks gfredericks, i'll try to figure that out. does seem shorter

21:23 turbofail: or you could do (into {} (map (juxt (comp keyword key) (comp :value val)) mymap)) if you want to be point-free (point-less?)

21:42 Steve_Miller: wow, so much to learn. is the first one with [[k {v :value}] mymap] just destructuring?

21:43 justin_smith: yes, that's a destructuring

21:56 Steve_Miller: thx. think i finally got it. never knew you could destructure a map with [], also never knew about juxt, so thx turbofail. i better go to the beginners channel

21:56 justin_smith: Steve_Miller: it's map entries that can be destructured with []

21:56 ,(first {:a 0})

21:56 clojurebot: [:a 0]

21:56 justin_smith: map entries are two element vectors

21:56 Steve_Miller: well.. i guess it's a map entry, yeah

23:27 justin_smith: gfredericks: in americaland, all dates in the coming week will be palendromic in the standard format

23:27 (or something approaching it)

Logging service provided by n01se.net