#clojure logs

2015-05-09

00:52TEttingerNiac: you still around?
00:54TEttinger,(java.awt.Toolkit/getDefaultToolkit)
00:54clojurebot#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...
01:57Niaccan anybody tell me how to use Graphic in clojure
03:08expezIf I have a protocol, how can I get at the generated java interface?
03:09expez(:on-interface AProtocol) returns what looks like a classname, but findClass throws an exception when I try to use it.
03:16expezheh, doing (compile 'my.ns) generated the interface
03:24kaffeeboehnchenWhat is the easiest way to find doubles in a lists? For example I have (1 2 1 4) and want the 1.
03:25tatutperhaps frequencies
03:26kaffeeboehnchenThanks, I'll try it out!
03:28kaffeeboehnchen(first (keys (frequencies list))) works :)
03:59kaffeeboehnchenok, not always
04:09TEttingerkaffeeboehnchen: do you want specifically doubles?
04:10TEttinger,(def one-or-two [1 2 1 4 3 3 5 7])
04:10clojurebot#'sandbox/one-or-two
04:12TEttinger,(defn appearing-twice [coll] (map first (filter (fn [[_ v]] (= v 2)) (frequencies coll))))
04:12clojurebot#'sandbox/appearing-twice
04:12TEttinger,(appearing-twice one-or-two)
04:12clojurebot(1 3)
04:14TEttingerif you want appearing more than once, specifically...
04:14TEttinger,(defn appears-multiple [coll] (map first (filter (fn [[_ v]] (> v 1)) (frequencies coll))))
04:14clojurebot#'sandbox/appears-multiple
04:15TEttinger,(def crazy-mix [1 2 1 4 3 3 3 5 7 7 7 7 7 7 9])
04:15clojurebot#'sandbox/crazy-mix
04:15TEttinger,(appears-multiple crazy-mix)
04:15clojurebot(1 3 7)
04:15kaffeeboehnchenTEttinger: Very cool, thanks!
04:16TEttingerhope it helps!
04:16TEttingerfrequencies is great
04:23kaffeeboehnchenTEttinger: What does [[_ v]] do?
04:23TEttingerdestructures the pair, binds the key to _ (which is commonly used as a name for unused variables) and the value to v
04:23kaffeeboehnchenOk, cool!
04:24kaffeeboehnchen(clojure beginner here)
04:24TEttinger,(map (fn [[_ v]] (+ v 1)) {:a 1, :b 2, :c 4})
04:24clojurebot(2 3 5)
04:25TEttingeror the other way around...
04:25TEttinger,(map (fn [[k v]] (str k)) {:a 1, :b 2, :c 4})
04:25clojurebot(":a" ":b" ":c")
04:25TEttingerand more importantly...
04:25TEttinger,(map (fn [[k v]] [v k]) {:a 1, :b 2, :c 4})
04:25clojurebot([1 :a] [2 :b] [4 :c])
04:27TEttingerthat 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
04:28TEttinger,(into {} (map (fn [[k v]] [v k]) {:a 1, :b 2, :c 4}) )
04:28clojurebot{1 :a, 2 :b, 4 :c}
04:29Niacimport java.awt.*;
04:30Niachow to write in repl
04:30ARM9I'm stumped http://benchmarksgame.alioth.debian.org/u64q/program.php?test=pidigits&lang=clojure&id=5
04:33TEttingerNiac: clojure does not have any import all thing. you can... (not sure if this bot can do it)
04:34TEttinger,(import 'java.math.MathContext)
04:34clojurebotjava.math.MathContext
04:34TEttinger,(MathContext. 1000)
04:34clojurebot#object[java.math.MathContext 0x851984b "precision=1000 roundingMode=HALF_UP"]
05:05wasamasawhat was the website again that did visualize the relations between libraries from clojars again?
05:10wasamasaah, found it: https://crossclj.info/
05:13wasamasakaffeeboehnchen: don't overdo destructuring though
05:14kaffeeboehnchenwasamasa: I'll keep it in mind. :)
06:00Niacquit
06:00Niacexit
06:03hellofunkexpel
07:02TEttingerRaynes: did you change the refheap API recently?
07:06expezGiven a name as a string, how can I get at the protocol by that name?
07:18GlenjaminYo, could anyone recommend a good place to ask about microservice deployment? (i know a bunch of people here are using such approaches)
07:19GlenjaminSpecifically, i'm wondering if it's worth having a separate unix user per service deployed
07:36tahmidI have a silly question
07:36tahmidHow to switch the value of an atom from true to false
07:36tahmidI need to write something like (swap! myatom func)
07:36tahmidwhat should be the func
07:36oddcully,(doc reset!)
07:37clojurebot"([atom newval]); Sets the value of atom to newval without regard for the current value. Returns newval."
07:37tahmidThanks
07:38scottjtahmid: if it's false do you want it to be true? (swap! myatom not)
07:38tahmidyes
07:39tahmidNice trick
07:41escherizeCheap hostels are kind of sketchy
08:25TEttinger$mail Raynes can you $mail me any information about API changes to refheap? I've been getting "failed to paste: peer not authenticated"
08:25lazybotMessage saved.
08:36nicferrieris there a pattern list for core async anywhere?
08:36nicferrierI do really enjoy working with it... but somtimes get tied in knots wondering how to sync things.
08:37nicferrierI'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
09:44anti-freezeHi 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?
09:45anti-freezeActually, the operation will never be dereferenced. So if I use a future, i'll never be using @(transfer-file ,,,)
09:46anti-freezeSo an asynchronous, uncoordinated operation
09:47anti-freezeBut it has side effects
09:48Glenjaminprobably future or thread
09:48Glenjamin(doc thread)
09:48clojurebotPardon?
09:48Glenjaminhrm
09:48Glenjamini could have sworn that existed
09:49tatutit's in core.async
09:49anti-freezeYea, I can't find (doc thread) either
09:49anti-freezeAh right. So, a future then?
09:49Glenjaminfuture for naive stuff, but be aware you might want a pool/queue if you're doing this a lot
09:50anti-freezeGlenjamin: Not really, just profile picture uploads. Futures run in native threads right?
09:50Glenjaminyes, but provide no control over how many run at once
09:51anti-freezeGlenjamin: Well, I guess not
09:51anti-freezeAlso, is it cool to log stuff from that future?
09:51tatutbut I'd suggest caring about the result of the execution :)
09:51Glenjaminsomething like core.async can help there, but (future) is fine for now
09:52tatutso the core.async thread is good because it returns a channel from which you can receive the result
09:53anti-freezetatut: 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?
09:54Glenjaminit's captured in the future
09:54tatutbut if you never deref it, you will not know about it
09:54Glenjamin,(future (throw (Exception. "abc")))
09:54clojurebot#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...
09:54Glenjamin$(future (throw (Exception. "abc")))
09:55Glenjaminanyway, the deref will re-throw, i'd suggest poking around your repl a bit :)
09:55anti-freezeAlright, thanks guys
09:56anti-freezeBy the way, agents aren't really what I want right?
09:57ConfusionistIs this a correct core.typed signature: (ann foo (Fn [Any -> String] [Any Any -> String])) ?
09:58ConfusionistOn the line where foo is subsequently declared, I get First argument to TApp must be TFn, actual: clojure.lang.Fn
09:58anti-freezeAlso, seems like it doesn't work with futures, only with dosync.
09:58anti-freezeBecause I'm never dereferencing the future
09:58anti-freezeI think?
10:00omhow do you add deps to the classpath dynamically in the boot repl?
10:01omat the moment, I set-env! the deps and run the aot task on the namespace
10:01omdoes it sound like standard practice?
10:01ConfusionistHmmm... cf returns an IFn in the signature
10:04anti-freezeJust do be clear, dosync executes stuff in a different thread right?
10:05hyPiRionanti-freeze: no
10:06anti-freezehyPiRion: So, I have to use futures then I guess
10:09hyPiRionanti-freeze: I'd use that to start out with.
10:31supersymIs it ok/possible to add new methods to a protocol definition (meaning extend-protocol but with their virtual methods, not the concrete realizations)?
10:33ConfusionistIf 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:41supersymConfusionist: no... in-ns doesnt try to make a ns symbol, ns does
10:41justin_smithsupersym: that's wrong - in-ns will create an ns if it does not exist
10:41clojurebotI don't understand.
10:42supersymoh ... you are right
10:42supersymmy bad (memory)
10:43justin_smithafter running in-ns and creating an ns, one will usually want to run (clojure.core/refer-clojure)
10:43justin_smithif only so you can then access in-ns again to get back into the right ns :)
10:44dnolensupersym: not aware that anything like that is possible wrt protocols
10:44ConfusionistSo 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:44supersymdnolen: thanks
10:45ConfusionistAnd the file in which I (load "file") starts with (ns app.core) in which it requires clojure core.typed.
10:45ConfusionistThat's all of the code. Should ns and in-ns behave differently in this way?
10:46supersymIve only seen cases of in-ns used that way, that is not to say, the other method shouldn't work
10:46supersymthat is, in conjunction with load
10:56dnolencfleming: btw, find symbol seems to not work so well for symbols in .cljc files
11:00supersymoh I see I don't really have to.. defrecord supports multiple specs so I can stack new ones in their own protocol, figures.
11:54n8dawghi 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:55kaiyinIs there an alternative for (Class/forName "[[D")? This is causing some error in cursive.
12:01puredangern8dawg: see pipe
12:02hyPiRionuh
12:02hyPiRion,(subseq (into (sorted-set) (range 5 10)) <= 0 <= 100)
12:02clojurebot(6 7 8 9)
12:02hyPiRionshouldn't that one actually return (5 6 7 8 9) ?
12:04hyPiRionnvm, it should be (... >= 0 <= 100).
12:09jsnikerisHi 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:09jsnikerissteps 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:12n8dawgpuredanger: its not quite pipe i'm after. I'll paste some code
12:12n8dawg(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:13n8dawgpuredanger: basically i want writes to go to an input channel, and reads to come from an output channel
12:34hellofunkn8dawg: please use something like refheap or github gist to share code rather than pasting into the chat window
12:59brainproxyjsnikeris: you can wrap the body of each function definition in a go block
13:00brainproxybut the bigger picture is that "go-ing async" is a decision which tends to ooze through other parts of your code base
13:01brainproxythat being said, remember that the double-bang variants don't have to be used in a go block
13:01brainproxybut they will truly block the thread in which they're used
13:43tahmidI can’t get figwheel to work
13:43tahmidHere’s my project.clj
13:43tahmidhttp://pastebin.com/6EPJcXzR
13:44tahmidAnd I am getting this error java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number
13:51tahmidIssue is solved
13:51tahmid:server-port should have been a number , not a string
13:52tahmidThanks to justin_smith for pointing that out
13:52tahmid(+ 2 justin_smith)
14:20kaiyin,(condp some [1 2 3 4] #{0 6 7} :>> inc #{4 5 9} :>> dec #{1 2 3} :>> #(+ % 3))
14:20clojurebot3
14:20kaiyinwhy does this return 3?
14:21kaiyinI would expect 2.
14:21justin_smith(some #{4 5 9} [1 2 3]) -> 4 -> dec -> 3
14:22justin_smitherr, I meant [1 2 3 4] of course
14:23kaiyinjustin_smith: ah, i thought it was (some [1 2 3 4] #{4 5 9}). ok, got it.
14:24justin_smith,(some [1 2 3 4] #{4 5 9})
14:24clojurebot#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:25justin_smith,(some #{4 5 9} [1 2 3 4])
14:25clojurebot4
14:38Viestimmh
14:40Viestiwas baffled by a clojure.tools.namespace.repl/refresh + http-kit handler reload problem for a while
14:40justin_smithwhat was the issue?
14:41Viestihad (run-server #'handler ...) and refresh didn't reflect changes until using (disable-unload!) in the namespace
14:42ViestiI guess the thing is that refresh unloads the whole namespace, recreates it and so (run-server ...) ends up holding some old var
14:42Viestiring reload middleware tracks changed namespaces and does (require :reload)
14:42justin_smithyeah, dereferencing the old var would give you the old contents
14:43Viestiyep
14:43justin_smithif the whole namespace is created from scratch
14:43Viestijust feeling a bit stupid now :P
14:43Viestianyways, saying it out loud cleared by thoughts :)
14:44Viestia good refreshment for me on how vars and reloading work
14:46Viestiwas 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:57justin_smithViesti: another option would be putting the server in a component, and running (stop) (refresh) (start)
14:58justin_smiththen you don't need to provide the var either
14:58ConfusionViesti, you've seen this: http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded?
14:59ConfusionIf not, there may be something useful in there
14:59tahmid,(vec [[1] [2] [3]])
14:59clojurebot[[1] [2] [3]]
14:59Viestiyep, read that, using https://github.com/weavejester/reloaded.repl in another project
14:59Viestithe thing was that I didn't want to stop the server while reloading
15:00ViestiI'd normally make a server component so that on Licecycle/stop it actually gets stopped
15:02Viestiin the component case a new system would get created in the reload cycle, old one discarded
15:03Viestiin this case I wanted to keep the server around, just pass new code for the hander :)
15:03Viestibut still be able to reload namespaces in dependency order
15:04tahmidI have this vector [[1] [2] [3]]
15:05tahmidHow can I turn it into this [1] [2] [3]
15:06ConfusionViesti, understood. Stopping and reloading is easy :)
15:08Viestitahmid: are you looking for something like this? http://stackoverflow.com/questions/5232350/clojure-semi-flattening-a-nested-sequence
15:09Confusiontahmid, what are you subsequently going to do with those 3 vectors?
15:09tahmidput them inside a hiccup div
15:10tahmid[:div (for [x vec-of-elements] x)] -> this gives me a list of individual vectors
15:11seangroveAh, 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:13Confusiontahmid, push the :div into the vec using something like (vec (cons :div [[1] [2] [3]]))?
15:14Viestiseangrove: maybe :exclusions for the jackson stuff on datomic-pro might help?
15:16seangroveViesti: Added a bunch of exclusions elsewhere, and then added in explicit dependencies on the jackson stuff, seems like a bit of progress
15:16Viestihum, maybe this could also work (let [xs [[1] [2]]] `[:div ~@xs])
15:16Confusion,(into [:div] [[1] [2] [3]))
15:16clojurebot#<RuntimeException java.lang.RuntimeException: Unmatched delimiter: )>
15:16Viestiseangrove: hope it works :)
15:16Confusion,(into [:div] [[1] [2] [3]])
15:17clojurebot[:div [1] [2] [3]]
15:23tahmid[:div (for [x vec-of-elements] x)] this worked
15:24tahmid:viesti :Confusion Sorry I got disconnected from the net
15:26Viestitahmid: Confusion mentioned this: (into [:div] [[1] [2] [3]])
15:26Viesti,(into [:div] [[1] [2] [3]])
15:26clojurebot[:div [1] [2] [3]]
15:27Viestiprobably better than the idea that I had
15:27tahmidViesti: I was looking for something like that, You guys are so awesome
15:27Viesti,(let [xs [[1] [2]]] `[:div ~@xs])
15:27clojurebot[:div [1] [2]]
15:27Viestithanks :)
16:44jsnikerisbrainproxy: 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:58kaiyinThese two are the same, right? (condp = i 0 1 1 0) (case i 0 1 1 0)
17:00turbofailthey don't have identical performance
17:05gfredericks,(with-redefs [= not=] (let [i 1] (condp = i 0 1 1 0)))
17:05clojurebot1
17:06gfredericks,(with-redefs [= not=] (let [i 1] (case i 0 1 1 0)))
17:06clojurebot0
17:31kaiyingfredericks: that was a clever hack. :)
17:32kaiyinFrom the clojure programming book: In the long term, interfaces for core abstractions are planned to be replaced by protocols
17:32kaiyinIs this done in 1.7?
17:32puredangerno
17:33kaiyinok. how come it's already done in clojurescript?
17:33puredangerbecause clojurescript had the benefit of hindsight
17:33kaiyinok
17:34puredangerprotocols didn't exist till several years into Clojure (but before the ClojureScript impl was written)
17:36gfrederickspuredanger: has there not been any moves in that direction because "it's a lot of work" or backwards compatibility concerns?
17:36gfredericksjust curious
17:37puredangerwell it's definitely a lot of work :)
17:37puredangerand likely very hard to make backward compatible
17:38puredangerand would likely be slower
17:38gfredericksoh right
17:38puredangerand users wouldn't gain many benefits
17:38Glenjaminthat's one of the dunaj things iirc
17:38gfredericksso it's fine in cljs because js doesn't have a core interface concept anyhow
17:39kaiyinclojurebot: dunaj
17:39clojurebotPardon?
17:39Glenjamin$google dunaj
17:39lazybot[Dunaj - Wikipedia, the free encyclopedia] http://en.wikipedia.org/wiki/Dunaj
17:39Glenjaminoh, probably not that
17:39gfrederickspuredanger: 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:39Glenjaminhttp://www.dunaj.org/
17:40puredangergfredericks: hard to say. lotta variables.
17:40puredangerthere are a number of places where we have hard-coded conditional logic (lot of RT methods)
17:41puredangerthat stuff sucks and is really fragile for inlining
17:41puredangerbut could potentially be faster with protocol style invocation
17:41gfredericksoh and those places could conceivably speed up with protocols you mean?
17:41gfredericksjinx
17:41puredanger*maybe*
17:41puredangerit would be a lot of work to find out :)
17:42gfredericksroger
17:42puredangerI'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:43gfredericksif not for those reasons, do it because people occasionally suggest it from time to time
17:43puredangeryes, good point
17:43Glenjaminit would probably make custom datatypes a bit easier
17:44Glenjaminespecially in cljc scenarios
17:44puredangeryou'd be extending protocols instead of extending interfaces
17:44puredangerdoesn't seem like it'd be much different
17:44puredangercould be more portable for sure
17:44Glenjamini 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:45Glenjaminmight have been existing types
17:45Glenjaminsomeone was around a few weeks ago struggling to port something from cljs to clj
17:46Glenjaminah yes, he was porting datascript
17:54andyfSo 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:55gfredericksphew
18:52kaiyinis it true that every java interface can be translated into a deftype equivalently?
18:52justin_smithkaiyin: you can make a deftype that instantiates any interface you like, if that's what you mean
18:52justin_smithbut they are two different kinds of things
18:56kaiyinok
18:58kaiyinthe way deftype behaves is very much like java.
18:59justin_smithit's true, it's like defining a java class that can only implement methods that alreayd exist in some interface
19:01kaiyinis there a way to mix java and clojure code? i mean MyClass.java directly, not through a jar file.
19:01justin_smiththe clojure compiler does not use javac
19:01kaiyinso the answer is no.
19:01justin_smithso, not really, without a big hack of some sort that would involve calling javac via a shell command I guess
19:02kaiyinok, i see. that's probably why we have deftype.
19:02justin_smiththere is also gen-class
19:08andyfalso definterface
21:00bostonaholicI'm creating a new clojure newsletter. Email me at clojure@airshiplabs.com for the latest news and tips on Clojure.
21:10Steve_MillerProbably easy for most here, but is there an easier way?
21:10Steve_Miller(def mymap {"company" {:value "something"} "accountNumber" {:value "store"}})
21:10Steve_Miller(reduce #(merge %1 %2)
21:10Steve_Miller (map #(hash-map (keyword (key %)) (:value (val %))) mymap))
21:12gfredericks,(def mymap {"company" {:value "something"} "accountNumber" {:value "store"}})
21:12clojurebot#'sandbox/mymap
21:12gfredericks,(into {} (for [[k {v :value}] mymap] [(keyword k) v]))
21:13clojurebot{:company "something", :accountNumber "store"}
21:14Steve_Millerthanks gfredericks, i'll try to figure that out. does seem shorter
21:23turbofailor you could do (into {} (map (juxt (comp keyword key) (comp :value val)) mymap)) if you want to be point-free (point-less?)
21:42Steve_Millerwow, so much to learn. is the first one with [[k {v :value}] mymap] just destructuring?
21:43justin_smithyes, that's a destructuring
21:56Steve_Millerthx. 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:56justin_smithSteve_Miller: it's map entries that can be destructured with []
21:56justin_smith,(first {:a 0})
21:56clojurebot[:a 0]
21:56justin_smithmap entries are two element vectors
21:56Steve_Millerwell.. i guess it's a map entry, yeah
23:27justin_smithgfredericks: in americaland, all dates in the coming week will be palendromic in the standard format
23:27justin_smith(or something approaching it)