#clojure logs

2015-12-07

01:20kenrestivois there any way to make networking code less... ugly? i wrote this but i hate it: https://www.refheap.com/112427
01:21kenrestivoit's for a component. it seems like a tangled unreadable mess. but i can't think of any other way to do it.
01:28tolstoyHm. I wonder if Aleph's client libs would help.
01:28kenrestivoit might, though it has its own complexities
01:29kenrestivomy end goal here is a component that wraps mqtt in core.async
01:29tolstoyAre you working with activemq?
01:29kenrestivomosquitto in this case
01:29tolstoyOh, right. Okay
01:30tolstoyHm. When I used to do this using actors, I'd have one actor that represented the connection, and another "linked" actor that was the supervisor.
01:30tolstoyWhen the connection actor threw an exception and died, the "link" mean that the supervisor actor got the message and could restart.
01:30tolstoySo, I wonder if you could do something similar?
01:31kenrestivohmm, that might work.
01:31tolstoyOn "go-loop" that manages the connection. If there's an error (.isConnect conn) or something, it drops a message in the "super" channel, then does.
01:31tolstoyThe super channel just waits for that message and tries a reconnect.
01:32kenrestivoi like that, thanks.
01:33tolstoyDecomplects connection stuff from supervisor stuff? Gotta be some Clojury conference-circuit way of phrasing it.
01:34tolstoymqtt seems kinda neat.
02:46copycatwhat does this look like? i'm not sure how to visualize this
02:46copycat(vec (map vector
02:46copycat (map + (range length) (repeat xpos))
02:46copycat (repeat ypos))))
03:03visof,(merge-with conj {:hello {:x 1 :y 3 :other [4 5 6]}} {:hello {:x 3 :y 1 :other [3]}})
03:03clojurebot{:hello {:x 3, :y 1, :other [3]}}
03:04visofhow can i merge values of the same keys to a list
03:04visofto be {:hello {:x [1 3] :y [3 1] :other [[4 5 6] [3]]}} ?
03:04TEttinger,(merge-with list {:hello {:x 1 :y 3 :other [4 5 6]}} {:hello {:x 3 :y 1 :other [3]}})
03:04clojurebot{:hello ({:x 1, :y 3, :other [4 5 6]} {:x 3, :y 1, :other [3]})}
03:05TEttingerwait no that's awful :)
03:05opqdonutyou need deep-merge-with
03:05TEttinger,(merge-with list {:hello {:x 1 :y 3 :other [4 5 6]}} {:hello {:x 3 :y 1 :other [3]}} {:hello {:x 2 :y 2 :other [1 5]}})
03:05clojurebot{:hello (({:x 1, :y 3, :other [4 5 6]} {:x 3, :y 1, :other [3]}) {:x 2, :y 2, :other [1 5]})}
03:06TEttingerthat's why that's awful
03:06opqdonutyeah
03:07visof,(deep-merge-with conj {:hello {:x 1 :y 3 :other [4 5 6]}} {:hello {:x 3 :y 1 :other [3]}})
03:07clojurebot#error {\n :cause "Unable to resolve symbol: deep-merge-with in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: deep-merge-with 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 s...
03:07visofis it at other lib
03:07opqdonutI don't know
03:07opqdonutI've defined it myself
03:08opqdonutmight be in some library with some other name
03:08opqdonutbut conj is wrong anyway
03:08opqdonutor it's ok if you get the empty sequences from somewhere
03:08opqdonute.g. like this:
03:09opqdonut,(merge-with conj {:x [] :y []} {:x 1} {:x 2 :y 3} {:x 3 :y 4})
03:09clojurebot{:x [1 2 3], :y [3 4]}
03:09visofopqdonut: ah ok
04:04dxtr_hi
04:05dxtr_is "the joy of clojure" still up to date? or should i be looking at some other book to get started?
04:11ARM9it's still mostly up to date, it probably still recommends that "use" be used instead of recommending require
04:16tolstoyOn a recent podcast, Stuart Holloway mentioned that all the code in his pre-1.0 Clojure book still runs.
04:17tdammersas in, he fired up a repl and loaded the code, and that repl is still running?
04:24Glenjaminjoy of clojure 2nd edition is less than a year old i think
10:35njorthgp /st
10:48ToxicFrogSo, here's a question I haven't needed to ask in ages, such that I've forgotten the answer
10:48ToxicFrogWhat's the easiest way to just write a one-off .clj script and shebang it?
10:49ToxicFroglein doesn't seem to have a "lein run-script" command
10:52tdammersnot usually viable, startup time tends to be prohibitive for this kind of thing
11:02schmirToxicFrog: https://github.com/boot-clj/boot/wiki/Scripts
11:03ToxicFrogschmir: that's specific to having the Boot tool installed
11:04ToxicFrogIt looks like the answer I actually want is: exec java -cp ~/.m2/repository/org/clojure/clojure/$VER/clojure-$VER.jar clojure.main "$@"
11:04ToxicFrogAnd then stuff that in a script I can put in the #!
11:05ToxicFrogtdammers: it turns out that when not using lein, startup time is dramatically reduced
11:05ToxicFrogStill not something I'd want to use with, say, find -exec, but Good Enough for some things.
11:10ToxicFrogSigh.
11:11ToxicFrog"java.lang.Boolean cannot be cast to clojure.lang.Symbol, compiling:(.../2.clj:1:1)"
11:11ToxicFrogThe first four lines of this file are comments.
11:15ToxicFrogHmm.
11:15ToxicFrog(repeatedly read-line) looks like a good way to get a line-seq from *in*, since you can't just (line-seq *in*)
11:15ToxicFrogBut it NPEs on EOF.
13:20visofhi guys
13:26visofi code method which take some time, but i want to make it processed in the background and then run another fast code, i make this (do (future (long-time-method)) (short-time-method))
13:26visofand i still get longer time
13:27visofi just wnat long-time-method run in background and skip to short-time-method
13:27rhg135There is overhead, but how much longer?
13:34visofrhg135: what do you mean with how much longer?
13:35beakyi have crap shoulders, tspine, and squat mobiltiy
13:35beakyoops wrong channel
13:37rhg135visof: spinning up a thread incurs overhead from scheduling. Usually it should just be a few ms per thread. Also your code seems correct.
13:39visofrhg135: is there a method to do this in a more efficient way, what if my long-time-method take 1 min, i and don't want the user wait this time
13:42justin_smithvisof: the do block takes the amount of time to dispatch the future, plus the time of short-time-method - the run time of long-time-method will not affect it unless long-time-method is heavy enough to lock up basically your whole computer
13:42rhg135It depends. In languages without threads you would use callbacks
13:43rhg135But that's not a good fit sometimes
13:44justin_smithcallbacks are about coordination, not processing - a callback might run on a different thread, it might run on the same thread
13:47rhg135justin_smith: I'm assuming callbacks being independent from threads here
13:48rhg135In practice, not usually
13:51rhg135Oh right. Yes, justin_smith is correct. I don't know what I'm thinking
13:52rhg135You can't do parallel execution on the jvm without threads
13:53justin_smithcallbacks are good if you don't have threads and still have things that need to be done concurrently, or if you need to let some other part of the system have the control of the timing or conditional execution of your code
13:55rhg135They're great except for the inversion of control
14:44fuddu-coderi have a collection of java objects. what would be the best way to figure out distinct objects in the collection based on certain fields
14:44fuddu-coderthe fields would be extracted through interop ofcourse
14:45fuddu-coder,(+3 4)
14:45clojurebot#error {\n :cause "java.lang.Long cannot be cast to clojure.lang.IFn"\n :via\n [{:type java.lang.ClassCastException\n :message "java.lang.Long cannot be cast to clojure.lang.IFn"\n :at [sandbox$eval25 invokeStatic "NO_SOURCE_FILE" 0]}]\n :trace\n [[sandbox$eval25 invokeStatic "NO_SOURCE_FILE" 0]\n [sandbox$eval25 invoke "NO_SOURCE_FILE" -1]\n [clojure.lang.Compiler eval "Compiler.java" 6943]...
14:45justin_smithfuddu-coder: maybe something like (group-by #(.foo %) objects)
14:45ridcully,(+ 3 4)
14:45clojurebot7
14:47fuddu-coderjustin_smith: true. but i would liek to have a combination of fields determine the distinctness. does that make sense
14:47fuddu-coder*like
14:47justin_smithfuddu-coder: hmm so would you want one map where you look up based on the set of fields they have, or one grouped map for each field, or?
14:48fuddu-coderone map where you look up based on the set of fields they have
14:48ridcullyor type
14:49justin_smithso make set-of-fields - a function that takes an object and returns a set of relevant fields
14:49ridcullycould you elaborate on what the differences are there?
14:49justin_smiththen group-by set-of-fields
14:50fuddu-coderyup. that would be one way to go.
14:52sdegutisClojure's first commit: https://github.com/clojure/clojure/commit/894a0c81075b8f4b64b7f890ab0c8522a7a9986a
14:52justin_smithfuddu-coder: seems the simplest thing - then you could derive "all objects with field X" by filtering the keys for that field and merging all vals the keys match
14:54ARM9sdegutis humble beginnings
15:08sdegutisARM9: aint it ho
15:08sdegutis*tho
15:09TimMcIn the beginning there was a cons cell, a symbol, and scope.
15:13sdegutisAnd a single namespace?
15:14sdegutisCan someone ELI5 Rich's hair? https://github.com/richhickey
15:14sdegutisis that a NY thing or something?
15:15ARM9looks ready to party like it's 1984
15:17TimMcThere is no need to explain. His hair is amazing and that is all.
15:19TimMcHe probably takes the same appoach to fashion I do: Pick a style and let it come around again and again. :-D
15:36sdegutisTimMc: haha that's too much work
15:36clojurebotHuh?
15:36sdegutisTimMc: my approach is to just shave my head every 2 weeks; never have to worry about styling it, and shampooing it is way easy&quick
15:37sdegutisplus its not too hot in the summer this way; and in the winter i can just wear a hat. done.
15:39TimMcOh, I meant overall style, not just hair... but I keep my hair in a ponytail for a similar reason. Very little work.
15:39sdegutisoh
15:39sdegutishaha yeah
15:39sdegutisnice
15:40TimMcBut really I find very little profit to be had in analyzing people's appearance...
15:43TimMcHowever, I will criticize the heck out of his use of whitespace.
15:45amalloy"use" is a strong word. reading compiler.java it sometimes seems like his keyboard is just on the fritz
15:46Bronsait's just postmodern indentation
15:47TimMcI wonder if that's what happens when you try to write Java in emacs without good indentiation settings and you're just fighting the mode the whole time.
15:47BronsaTimMc: more likely it's what happens when you switch editors and IDEs
15:52justin_smithWhitesmiths style https://en.wikipedia.org/wiki/Indent_style#Whitesmiths_style
15:54ecmikeno likey
15:55ecmikeAllman is ok though
15:55justin_smiththat wiki page "lisp" style example is wrong in at least two ways - lisp indent applied to algol lang, and hanging open brace
15:55TEttingerhuh, Allman is what I use. never knew the name
15:56justin_smithmany GNU projects use K&R
15:56ecmikeI get annoyed with lines that are purely syntax symbols though, it's unnecessary cognitive noise
16:11OrbitalKittenhey guys, is there a reason why \ evaluates to \newline when used 'naked' in the repl and seems to evaluate to a space when used in a function (eg. (str "Hello" \ "World"))?
16:15amalloybecause the character you typed after the \ in your repl was a newline
16:15TimMcOrbitalKitten: You had to hit newline twice in order to enter it in the REPL, yeah?
16:15TimMcIt can take either a literal like \™ or a code like \space and what you gave it was a literal newline. :-)
16:15OrbitalKittennot sure
16:15pbxOrbitalKitten, also at end-of-line in the REPL it's the line contunuation character
16:15OrbitalKittenoh
16:16OrbitalKittenI get it
16:16TimMc(To be clear, \newline is a much better idea.)
16:16pbxnevermind what i just said about line continuation, that looks to be false :\
16:16OrbitalKittenI will test that in the terminal, maybe it's cider doing weird things.
16:17OrbitalKittenHmm, my bad, cider inserts the newline automatically, I indeed had to tap entre twice
16:50fuddu-codernoob here. can i pass multiple functions to a map . is so which one among this can help me
16:50fuddu-coderhttp://clojuredocs.org/clojure.core/map
16:52beaky,(map (juxt inc dec) [0])
16:52clojurebot([1 -1])
16:53fuddu-coderyo.. thx.. juxt can help me. cool
16:53beaky,(map (juxt inc dec) [0 1 2 3])
16:53clojurebot([1 -1] [2 0] [3 1] [4 2])
16:53beaky,(map (juxt inc dec id) [0 1 2 3])
16:53clojurebot#error {\n :cause "Unable to resolve symbol: id in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: id 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: id in this context"...
16:53beaky,(map (juxt inc dec identity) [0 1 2 3])
16:53clojurebot([1 -1 0] [2 0 1] [3 1 2] [4 2 3])
16:53beaky:D
16:55WorldsEndlessI can convert .docx to pdf on disk, and I can merge pdf on disk. But I'm trying to take the "on disk" part out of the equation and go straight from my mongodb -> docx -> pdf -> merged pdf -> to client. Anyone have experience with something like this?
16:55WorldsEndlessMy java stream-fu is a little weak, and it's tripping me up
16:56justin_smithWorldsEndless: you can cheat on linux with an in-memory filesystem mounted on tmp
16:56justin_smithWorldsEndless: what are the requisite classes for the methods?
16:56justin_smithsometimes bad APIs force you to use files, and then you are stuck
16:57WorldsEndlessI'm using org.docx4j for the doc manipulation, and org.apache.pdfbox for the PDF stuff, and some don't have javadocs to help out...
17:00amalloyjustin_smith: not necessarily stuck, if they only read/write the files sequentially; you can use a named pipe then
17:01WorldsEndlessI'm able to write straight from mongo to a client using a clojure.java.io/piped-input-stream (which seems obnoxiously difficult to find docs for)
17:01WorldsEndlessBut in that case I'm missing both the to-PDF and the merge-PDF steps
17:07TimMcjustin_smith: I use a ramdisk to speed up clojure compilation. :-D
17:25sdegutisHi
17:31m1dnight_How hard would it be to implement a lein plugin that searches for unused imports/uses?
17:31m1dnight_I need a new pet project and that comes to mind. Ive discussed here a while back.
17:33beakyits probably easy
17:34amalloym1dnight_: long ago technomancy did that with slamhound. if you were going to revive the project you'd probably use tools.analyzer
17:36m1dnight_Oh, I have the git right here.
17:36m1dnight_Lets see how hard this will be :>
17:36TimMceastwood, I think
17:37m1dnight_Oh, eastwood does that?
17:37m1dnight_Darnit
17:37m1dnight_Late to the party :>
17:37visofhi guys
17:38visof,(str [+ -])
17:38clojurebot"[#object[clojure.core$_PLUS_ 0x2dc40f40 \"clojure.core$_PLUS_@2dc40f40\"] #object[clojure.core$_ 0x468bf604 \"clojure.core$_@468bf604\"]]"
17:38visof,(str '(+ -))
17:38clojurebot"(+ -)"
17:38visofhow can i get the last output from the first input which is [+ -] ?
17:38visofhow can i get "(+ -)" from input [+ -] ?
17:40TimMcm1dnight_: Dunno if it handles both imports and uses...
17:40MJB47,(str (seq '[+ -])) ; visof ?
17:40clojurebot"(+ -)"
17:41visofMJB47: input should be [+ -] not '[+ -]
17:41visof,(str (seq [+ -]))
17:41clojurebot"(#object[clojure.core$_PLUS_ 0x2dc40f40 \"clojure.core$_PLUS_@2dc40f40\"] #object[clojure.core$_ 0x468bf604 \"clojure.core$_@468bf604\"])"
17:41rhg135Macro !
17:41MJB47yup, use a macro imo
17:42rhg135The correct use: endowment of syntax
17:45MJB47visof: also you could do
17:45MJB47,(str (seq (quote [+ -])))
17:45clojurebot"(+ -)"
17:46TEttingerwhy quote?
17:46visofMJB47: thanks
17:46MJB47' is just syntactic sugar for '
17:46TEttingeryou don't need quote
17:46MJB47quote*
17:47TEttinger,(str (seq [+ -]))
17:47clojurebot"(#object[clojure.core$_PLUS_ 0x2dc40f40 \"clojure.core$_PLUS_@2dc40f40\"] #object[clojure.core$_ 0x468bf604 \"clojure.core$_@468bf604\"])"
17:47TEttingeroh
17:47TEttingerthat thing
17:47TEttinger,(pr-str (seq [+ -]))
17:47clojurebot"(#object[clojure.core$_PLUS_ 0x2dc40f40 \"clojure.core$_PLUS_@2dc40f40\"] #object[clojure.core$_ 0x468bf604 \"clojure.core$_@468bf604\"])"
17:47m1dnight_https://vimeo.com/80650659 # That voice. Such manliness. Such awesome.
17:51MJB47visof: incase you cared, the macro would look like: (defmacro m [body] `(str (seq '~body)))
18:15WorldsEndlessAnyone know where I can find the docs for java.io/piped-input-stream ?
18:19justin_smith,(doc clojure.java.io/piped-input-stream)
18:19clojurebotHuh?
18:19WorldsEndlessyeah...
18:20justin_smith,clojure.java.io/piped-input-stream
18:20clojurebot#error {\n :cause "No such var: clojure.java.io/piped-input-stream"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: No such var: clojure.java.io/piped-input-stream, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "No such var: clojure.java.io/piped-inpu...
18:20justin_smithWorldsEndless: what makes you believe this thing exists?
18:20WorldsEndlessBecause it's in my code, and it's working...
18:21justin_smithWorldsEndless: the clojure I have doesn't have any such var
18:21WorldsEndlessoops. I had the wrong ns
18:21WorldsEndlessIt's in ring...
18:21WorldsEndlessWhich would be why I've been struggling to fidn the docs
18:21justin_smiththat would explain not finding the docs
18:22justin_smithmore evidence that use shouldn't be used
18:22WorldsEndlessHa :) I wasn't using "use" but had it as io/piped-input-string and hadn't looked at the ns declaration recently enough to see that io in this file wasn't io as I have it in other files
18:23WorldsEndlessAnd yet, it's still a decent example of possible problems with "use" :)
18:23justin_smithheh
18:26visof,(defmacro m [body] `(str (seq '~body)))
18:27clojurebot#'sandbox/m
18:27visof,(m [+ -])
18:27clojurebot"(+ -)"
18:27visof,(def op [+ -])
18:27clojurebot#'sandbox/op
18:27justin_smith,(m (range))
18:27clojurebot"(range)"
18:27visof(m op)
18:27justin_smithhaha
18:27visof,(m op)
18:27clojurebot#error {\n :cause "Don't know how to create ISeq from: clojure.lang.Symbol"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "Don't know how to create ISeq from: clojure.lang.Symbol"\n :at [clojure.lang.RT seqFrom "RT.java" 535]}]\n :trace\n [[clojure.lang.RT seqFrom "RT.java" 535]\n [clojure.lang.RT seq "RT.java" 516]\n [clojure.core$seq__4116 invokeStatic "core.clj" 137]\n [...
18:27justin_smith,(m (mop))
18:27clojurebot"(mop)"
18:28visof,(m (op))
18:28clojurebot"(op)"
18:28justin_smith,(m (m bop))
18:28clojurebot"(m bop)"
18:28justin_smithsorry, terrible song
18:28visof,(m (op))
18:28clojurebot"(op)"
18:28justin_smithvisof: macros are tricky
18:28visofhow can i replace op with actual [+ -]
18:29visofjustin_smith: yeah it's
18:31justin_smith,(def mm #(map name %))
18:31clojurebot#'sandbox/mm
18:31justin_smith,(mm op)
18:31clojurebot#error {\n :cause "Unable to resolve symbol: op in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: op 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: op in this context"...
18:32justin_smith,(def op [+ -])
18:32clojurebot#'sandbox/op
18:32justin_smith,(mm op)
18:32clojurebot#<ClassCastException java.lang.ClassCastException: clojure.core$_PLUS_ cannot be cast to clojure.lang.Named>
18:32justin_smithergh
18:32justin_smith,(def op [#'+ #'-])
18:32clojurebot#'sandbox/op
18:32justin_smith,(mm op)
18:32clojurebot#<ClassCastException java.lang.ClassCastException: clojure.lang.Var cannot be cast to clojure.lang.Named>
18:32justin_smith:P
18:34justin_smith,(defn mm [vars] (map (comp :name meta) vars))
18:34clojurebot#'sandbox/mm
18:34justin_smith,(mm op)
18:34clojurebot(+ -)
18:34justin_smithbut that only works with the vars, not the functions - functions don't have names
19:34didibusCan I create a null from Clojure?
19:34justin_smith,nil
19:34clojurebotnil
19:34superstructornil has the same value as Java null
19:35didibusHum
19:35didibusI call (str "null:" nullObj)
19:35didibusAnd I get aNullPointerException
19:35didibusbut if I do ,(str "null: " nil)
19:35didibusit works
19:35didibus,(str "null: " nil)
19:35clojurebot"null: "
19:36amalloymmmmm, that's possible only because nullObj is not in fact nil
19:36amalloyrather it's some sort of lazy thing that realizes itself when you try to print it, and the thing it was lazily putting off doing causes an exception
19:36justin_smithdidibus: is the object null? what if it has a toString that is getting the NPE?
19:36didibusoh, actually, I thought it would print nil, but it prints blank, so it's probably something later on that throws the null pointer
19:37justin_smith,(pr-str nil)
19:37clojurebot"nil"
19:37justin_smithif you want a less ambiguous printout
19:37didibusOh cool, is that in core?
19:37justin_smithyes
19:37justin_smithsee also prn, pr
19:41didibusoh, that does'nt help me because (str) actually does not concatenate the nil
19:41justin_smithdidibus: you would use pr-str instead of str
19:41didibusOhhhhhhhhhhhhh
19:41justin_smithor inside it
19:41didibuslol, ok thanks, makes much more sense now
19:42justin_smith,(pr-str "OK: " nil)
19:42clojurebot"\"OK: \" nil"
19:42justin_smith,(str "OK: " (pr-str nil))
19:42clojurebot"OK: nil"
19:43didibusClojure just really has a function for everything lol
20:23ecmike,(pr-str "null: " nil)
20:23clojurebot"\"null: \" nil"
20:24ecmikeah, haha
20:24ecmike,(pr-str 1 2 'a)
20:24clojurebot"1 2 a"
20:39copycatwhat kind of error is this?
20:40copycatNo protocol method ReadPort.take! defined for type object: [object Object]
20:41copycatnot much results on google so... =(
21:13WickedShellcopycat, I'm assuming that thats from trying to use core.async reading from a channel? (If so I suspect its because the object passed isn't a channel).
21:13copycatyes, i found the bug. forgot to add in a function to return the channel =)
23:59dongcarlclojure newbie here, in this snippet: "loop [stack (:stack state), delims ""]", the comma serves to seperate the two bindings and nothing else right?
23:59justin_smithdongcarl: commas are whitespace