#clojure logs

2015-08-23

01:18kenrestivoi'm trying to use the clojure.edn/read-string to read a data structure that has dates like #<DateTime 2014-09-02T19:20:39.000-07:00> in them, and the reader is puking blood when confronted with this
01:18kenrestivoany hacks for reading such a file in?
01:19justin_smithkenrestivo: #<...> is the format for objects that are not readable
01:19justin_smithkenrestivo: recent clojure versions print #inst or #obj etc. instead
01:19justin_smith,(java.util.Date.)
01:19clojurebot#inst "2015-08-23T05:20:02.097-00:00"
01:20justin_smith,(java.util.HashMap.)
01:20clojurebot{}
01:20justin_smitherr...
01:20justin_smith,(Object.)
01:20clojurebot#object[java.lang.Object 0x298607bc "java.lang.Object@298607bc"]
01:20kenrestivoyeah, i know it's bad. i'm just wondering what to do with the file.
01:20justin_smithyou can actually make a reader for that at least
01:20kenrestivothis looks promising: https://gist.github.com/ragnard/4738185
01:20justin_smithkenrestivo: fix it with sed?
01:21kenrestivotrue, the sed brute force might be simplest. thanks
01:22justin_smithor even clojure.string/replace come to think of it
01:23kenrestivoreplace would work, i'm slurping it in, can do that before calling the reader
01:25kenrestivo(-> f slurp (string/replace #"#<DateTime (.+?)>" "#inst \"$1\"") (clojure.edn/read-string)) ;; works
01:26justin_smithwow, how retro, it's like perl or something :)
01:26justin_smithhmm
01:26justin_smith,(str (java.util.Date.))
01:26clojurebot"Sun Aug 23 05:26:37 GMT 2015"
01:26justin_smith,(str [(java.util.Date.)])
01:26clojurebot"[#inst \"2015-08-23T05:27:01.913-00:00\"]"
07:15hyPiRionhmm
07:15hyPiRion,(pr (java.util.Date.))
07:15clojurebot#inst "2015-08-23T11:15:27.806-00:00"
07:57lunaticleo,(java.util.Date.)
07:57clojurebot#inst "2015-08-23T11:57:20.530-00:00"
09:39xtrntrhi, noob here
09:39xtrntri don't think my terminal is making any progress on lein cljsbuild auto
09:39xtrntri always have to use lein cljsbuild once
09:40xtrntri can't understand why, is it a common occurence?
09:40xtrntrplus compiling takes a super long time
09:50gfredericksxtrntr: it might be that it's using cached versions; I'd try changing/saving a file and see if that makes it do something
09:54oracle`
09:54oracle`ii
09:54oracle`/
09:54oracle`hi
09:56oracle`I am using re-com component modal-panel, it works well with PC, but on mobile android, the modal window show empty, althought it must has a modal window, since the underlying elements are hidden.
09:57oracle`does re-com work with mobile device?
09:58lokien_Hey, does anyone here use spacemacs?
09:59oracle`yes, I am using it. super good
10:01lokien_I have to invoke some command through m+x every time I open it
10:01lokien_Is there a better way of doing it?
10:01lokien_Like, add this command to startup
10:06oracle`you can put it to .spacemacs file
10:09lokien_oracle`: can you show me an example on pastebin or something?
10:25spaceplukhi, is there any portable timer library?
10:45novak`I'm compiling clojurescript using cljsbuild. I have set :compiler :output-to "target/classes/public/app.js" and :output-dir "target/classes/public/out, after lein cljsbuild auto" it produces corresponding code but that new dir's are not on classpath so I can't reach them through Compojure's (resources ...).
11:40justin_smiththe two obvious options are to change your output locations or to change your classpath
13:05ely-seIs there a library for storing Clojure data structures on disk using structural sharing? I want to store a lot of revisions of the same value that share a lot of data in memory initally, but with edn they don't exploit structural sharing anymore.
13:11gfredericksely-se: I think that would be pretty fancy
13:11gfredericksespecially if you expect the kind of structure sharing that the persistent data structures have
13:12gfredericksit would likely take a lot of time/computation/memory to do the serialization
13:12justin_smithgfredericks: ely-se: it would be tricky - like you would be *required* to read in and realize all the data, otherwise the sharing could break
13:13gfredericksunless you wanted to hack into the persistent data structures and mess with the internal nodes
13:14gfredericksI assume that's physically possible on the jvm but don't know for sure
13:19ely-seI'll just go with edn now and see if it becomes a problem. :p
13:19ely-setime for a shower
13:35justin_smithgfredericks: it seems like you could write a "compressor" that starts by observing existing structural sharing, then emits edn for all constituent shared pieces, maybe looking for extra sharing it could factor out, then generates minimal code to construct equivalent structures out of those pieces using normal conj operations
13:46pseudonymousIf I wanted to create a background task in addition to a ring server (currently running it all via leiningen) in which direction should I look ? I unfortunately have to do some periodic cleaning tasks..
13:48justin_smithpseudonymous: one easy way to do it is a core.async go-loop
13:48pseudonymousjustin_smith: I see - I'll go look in that direction, then. Thanks :)
13:48justin_smithyou could also consider a ScheduledExecutorService
13:49justin_smiththere's a lib from overtone that wraps ScheduledExecutorService called at-at
13:49pseudonymousOh, sort of a cron-job for Clojure. Interesting
13:50justin_smithyeah, ScheduledExecutorService is like a much more flexible cron
13:51pseudonymousHehe. In my hurry, I just typed "at-at" into Google's search field. Let's just say the library is competing with Star Wars :)
13:52justin_smithhaha
13:54richyciao
13:54richy!list
13:55richyciao
13:57ely-seciaojure
13:58gfredericksjustin_smith: yeah, walking the internal nodes
14:19kanjaI'm trying to get eastwood/squigly setup - I'm getting the same error as in this bug report: https://github.com/clojure-emacs/squiggly-clojure/issues/19 but adding squiggly to my global or local dependencies isn't fixing it. Any ideas on why it's not found or what I can do to properly install it?
14:26ely-sewhy do < and > and friends not use Comparable<T> interface?
14:26justin_smithbecause they can be faster if they specialize for numbers
14:26ely-segreat
14:38jonathanj(apologies if i've asked this before, i can never quite remember what i'm looking for)
14:39jonathanjhow do i do an "unzip": ['(a b) '(c d) '(e f)] => ['(a c e) '(b d f)]
14:40justin_smith,(apply map list '[[a b] [c d] [e f]])
14:40clojurebot((a c e) (b d f))
14:42jonathanjah, map takes varargs
14:42jonathanjthank you
14:42justin_smithnp
14:44justin_smithjonathanj: the cool thing it is a two way transform
14:44justin_smith,(iterate #(apply map list %) '[[a b c] [d e f]])
14:44clojurebot([[a b c] [d e f]] ((a d) (b e) (c f)) ((a b c) (d e f)) ((a d) (b e) (c f)) ((a b c) (d e f)) ...)
14:44jonathanj:)
14:45justin_smithit will keep repeating the two rotations over and over
14:45jonathanjmy only gripe is that (apply map list %) is not very obvious to a reader
14:45justin_smithit's definitely an idiom though
14:46justin_smithand if you go through step by step you can figure out what it would do - it's only a few functions
14:50jonathanjyeah, it's just unfortunately a bit wordy
14:58gfredericks(def zip (partial apply map list)) (def unzip zip)
15:14tmtwdhow do I do this example with threading? http://pastebin.com/tEMXfMAq
15:17oddcully(-> m :profile :name)
15:18tmtwdthanks
15:34tmtwdwhat is the point of get-in when we can just use shorthand (:name (m :profile)) instead of (get-in m [:profile :name])?
15:34justin_smithtmtwd: get-in works for keys that are not keywords
15:35justin_smith,(get-in {"a" [1 2 3]} ["a" 1])
15:35clojurebot2
15:36justin_smithtmtwd: also, sinec [:profile :name] is a normal data structure, I can construct it at runtime without using eval
15:45tmtwdjustin_smith, huh?
15:46justin_smithtmtwd: to alter (:name (m :profile)) I need to create a new form, which will require eval. To alter ["a" 1] I can use conj, or make a new vector
15:48TEttinger(inc justin_smith)
15:48lazybot⇒ 286
15:48TEttingerI hadn't thought about using code to generate get-in vectors
15:48justin_smithit's pretty powerful, and sometimes even useful
16:25rocasam_hi all
16:26rocasam_Are there any tech savy ICR people who can answer this question? - Can I use the same nickname when I want to be logged in on both my pc and Androd? So in multiple clients.
16:27gfredericksprobably not if I had to guess
16:27rhg135not via raw IRC
16:28rocasam_hmmm pitty, but not a disaster
16:28ely-serun a server that acts as an IRC client and connect to it from both machines :P
16:28rhg135you can set up a bouncer, a persistent weechat, or look to irccloud
16:29rhg135I personally do the first two, I run a shared znc with a weechat for myself
16:29ely-sefor bonus points, reinvent the wheel by writing said server in Clojure
16:30rocasam_I have irccloud in my Android
16:31rocasam_I am logged in there, but then the Hexchat client on my pc tells me the nick is already in use.
16:31rocasam_sorry am a total newby - I havent been in irc chat since the nineties!
16:31rhg135there's a web client for it
16:32rhg135that'll connect as your android
16:32rocasam_irccloud webclient?
16:32rhg135yeah
16:32rocasam_Ill check it out
16:34rocasam_works! thanks rgh135 :-)))
16:35rhg135np
16:35rhg135I actually used irccloud long ago before I bought my rpi
16:35ely-seI want to do temporal pattern recognition in Clojure.
16:36rocasamSeems to be working really well.
16:38rocasamWhat do you mean with rpi rhg135
16:39rhg135rocasam: I have a small ARM computer (called a raspberry pi) on which I run a znc server
16:40rocasamI get it, not the znc part, seems terribly difficult but fun :-)
16:41rhg135I only run the znc for benefit of others, I myself use weechat inside tmux
16:46rocasamGreat!
16:52tmtwdhttp://pastebin.com/pTrzrUVt how do I have default values to replace nil values with threading?
16:53rhg135(or (some-> seed stuff) default)
17:02oddcully(-> m (get-in [:profile :address :zip-code] "no zip code!")) ;P
17:02oddcullywhat's wrong with get-in?
17:02rhg135or that
17:02oddcullythat's silly
17:07tmtwdoddcully, thanks
17:08oddcullytmtwd: i put that up in jest. i find that hardly an improvement
17:08tmtwdeh
17:08tmtwdI misread it initially
17:08tmtwdmaybe you can't do it with threading
17:09oddcullythe version of rhg135 is nice, if you want to have -> in your code
17:10rhg135threading for map access, seems overkill
17:11rhg135but answering the question
17:13ely-senot sure why she doesn't want to tell her colleagues about it
17:13ely-seoops, wrong channel
17:16oddcullyyet i have used or/some-> in some recent code... now i wonder, why i have not used get-in
17:16rhg135not plain map access?
17:16rhg135if you require post-processing it seems decent
17:20oddcullynope. i tend to use cond-> for that. i assumed, that get-in nil would not work. but it does
17:21rhg135-> is not too bad as you can just macroexpand it to see what it would do
17:22rhg135a custom function loop otoh is much worse
18:20rhg135http://www.rhg135.com/posts/2015-08-23-var-or-fn.html I remember stumbling over this one
18:49tmtwddoes anyone know off hand what the nil is in om where (dom/li nil text)
18:53justin_smithtmtwd: empty properties for the li?
19:03monstaGood night, I have a question, how specify the port where i want the repl to connect in the project.clj?
19:05hyPiRionmonsta: ":repl-options {:port 4001}" for example
19:05justin_smithmonsta: https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L354 the relevant line in the example project.clj
19:06monstajustin_smith: Thank, I feel so stupid now
19:37camm_v222Hi, everyone. I'm new at clojure, what do you suggestme to learn about it. My goal is to create Android App's with clojure.
19:52AWizzArd,(.-length (byte-array 5)) ;; shouldn’t this return 5?
19:53clojurebot#error {\n :cause "No matching field found: length for class [B"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "No matching field found: length for class [B"\n :at [clojure.lang.Reflector invokeNoArgInstanceMember "Reflector.java" 308]}]\n :trace\n [[clojure.lang.Reflector invokeNoArgInstanceMember "Reflector.java" 308]\n [sandbox$eval25 invokeStatic "NO_SOURCE_FILE" 0]\n [s...
19:53justin_smith,(count (byte-array 5))
19:53clojurebot5
19:53AWizzArdSure, but I suppose that .length would be faster.
19:53justin_smithit would be if the class had such a field I guess?
19:53justin_smith,(.length (byte-array 5))
19:53clojurebot#error {\n :cause "No matching field found: length for class [B"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "No matching field found: length for class [B"\n :at [clojure.lang.Reflector getInstanceField "Reflector.java" 271]}]\n :trace\n [[clojure.lang.Reflector getInstanceField "Reflector.java" 271]\n [clojure.lang.Reflector invokeNoArgInstanceMember "Reflector.java" 315]\...
19:54AWizzArdAt least in Java there is a length property for Arrays.
19:54justin_smithAWizzArd: also for collections that store their own size, you can count on count to access that directly and not count item by item
19:54justin_smithAWizzArd: oh right, arrays don't have methods, so it's a static method on the Array class
19:54justin_smith,(Array/length (byte-array 5)) ; something like this
19:54clojurebot#error {\n :cause "No such namespace: Array"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: No such namespace: Array, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "No such namespace: Array"\n :at [clojure.lang.Util runtimeException "Util.java" 221...
19:55AWizzArd,(alength (byte-array 5))
19:55clojurebot5
19:55justin_smiththere we go
19:55AWizzArdOkay good, thx.
19:55justin_smithbut you can count on count to get the result in a fast way
19:55justin_smithif it is possible
19:56AWizzArdYeah, I am just not sure if hotspot would replace my call to count with the fastest possible call to .length – this would be interesting though, as my array has 125 million elements, and I need to traverse it many times.
19:56AWizzArdOtherwise I wouldn’t care and simply call `count`.
20:22justin_smithAWizzArd: woah, acording to criterium, count is quite a bit faster
20:23justin_smithAWizzArd: https://www.refheap.com/108656
20:32AWizzArdjustin_smith: Oh, this is certainly unexpected.
20:32AWizzArdjustin_smith: although… in the first case you bench the creation of the array itself too.
20:32justin_smithAWizzArd: no, see that I cancel it
20:33AWizzArdjustin_smith: ah k
20:33AWizzArdWell, surprising indeed. But good, that way I am totally forced to use count.
20:33justin_smithAWizzArd: update - its fastest with alength + hint, edited https://www.refheap.com/108656
20:34justin_smithAWizzArd: so if you are warning on reflection and using alength, that seems the best so far (now trying with count + hint)
20:34justin_smithAWizzArd: the diff. in performance between the three is kind of crazy
20:34AWizzArdjustin_smith: my first thought was that a hint was missing, but I saw only the first line where you had the (byte-array …) call, so it was implicitly hinted.
20:34justin_smithAWizzArd: hints do not work that way
20:34justin_smithsince any def can change a var at any time
20:35justin_smiththere are no implicit hints on def
20:35AWizzArdI mean that (alength (byte-array 5)) might work without reflection.
20:35justin_smithAWizzArd: since perf is so important to you, I'd definitely have reflection and boxing warnings turned on
20:36AWizzArdjustin_smith: I always have them in my project.clj template activated.
20:36justin_smithAWizzArd: sure, that would, hell if the compiler weren't so dumb it could sub in 5 at compile time :P
20:36AWizzArd(-:
20:36AWizzArdjustin_smith: thanks for this test though, it confirms my idea that alength could save time.
20:37justin_smithalso, criterium is totally worth adding to your profiles.clj / user
20:37justin_smithalways handy
20:37AWizzArdI have it in there too. I agree that it is an excellent default development tool.
20:37justin_smithyeah, so hinting doesn't affect "count" at all, but it makes a huge difference with alength
20:38AWizzArdYes, I guess that count is doing the dispatching, so I supposed it would be slower.
20:38justin_smithhttps://www.refheap.com/108656 one more update for the count / hint combo - showing basically no difference
20:39AWizzArdA type hint should in no case improve the performance of calling a clojure function.
20:39AWizzArdThe exception are the array functions – and those are probably not clojure functions, though they look that way, as the leading . is missing.
20:41justin_smith,(source alength)
20:41clojurebotSource not found\n
20:41justin_smith$source alength
20:41lazybotalength is http://is.gd/Xb2FWl
20:41justin_smithanyway, it's a function that just does an interop call
20:42justin_smithwith a handy inline annotation
20:42AWizzArdIndeed.
20:42AWizzArdMakes sense, as Rich knew that array users probably care for efficiency.
20:44AWizzArdBtw, is there some clever tool that allows me to recompile .java classes while a `lein repl` is running, and reloads the classes when I change the corresponding source file?
20:44AWizzArdSomething similar to this auto compiler for cljs.
20:45justin_smiththe methods in clojure.lang.RT are as you might expect https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L2201
20:45justin_smithAWizzArd: not that I know of...
20:46Bronsa02:39:19 <AWizzArd> A type hint should in no case improve the performance of calling a clojure function.
20:46Bronsaexcept when those functions are inlineable
20:46Bronsaor macros
20:46justin_smith(inc Bronsa)
20:46lazybot⇒ 119
20:46justin_smiththanks for clearing that up
20:47AWizzArdBronsa: so this seems to be the case with the array fns.
20:47Bronsayup
20:47AWizzArdIs inlineability the criterium, or is it inlineability plus they must be calling into Java?
20:48Bronsaobviously interop must play a part
20:48AWizzArdsi
20:48Bronsabut deftype field access is also interop, and Java isn't involved technically
20:50Bronsawhy the hell doesn't byte-array have a ^bytes type hinth though
20:50Bronsaah it doesn't need one
20:50justin_smithBronsa: I thought it was because I was using a var that the hint ended up being needed
20:50Bronsayeah
20:51BronsaI wish type hinting stuff like (def foo "bar") wasn't needed
20:51Bronsabut I guess it'd impact dynamicity
20:52Bronsa(I also wish vars used a different keyword for tagging their value rather than overloading :tag but that's another complaint)
20:54AWizzArdBronsa: why doesn’t byte-array need no ^bytes hint?
20:54Bronsait's inlined
20:55AWizzArdBronsa: I also think that implicit hinting of obvious defs would impact dynamicity. The users of the def have already compiled the exact method that has to be called. If we re-run a def with a different class as value those callers would all result in errors.
20:55Bronsayes
21:00rhg135any way to make lein repl outside a project use clojure 1.7? I miss my transducers
21:01AWizzArdBronsa: perhaps in future versions, especially when core.typed advances its type inference even more, we will have the option to choose to omit dynamicity and have such automatic behaviour.
21:02AWizzArdrhg135: never tried it, but can you add Clojure 1.7 to your profiles.clj maybe and see if that changes anything?
21:03rhg135nope
21:04rhg135dummy project it is
21:05rhg135or boot
21:09justin_smithrhg135: are you tied to using nrepl? otherwise without a project def you can get super fast startup by just calling clojure.jar directly
21:10rhg135I am for now, justin_smith. I'm using vim fireplace
21:11justin_smithrhg135: you could also invoke `java -cp clojure-1.7.jar:some-nrepl.jar clojure.nrepl/start-server
21:11justin_smithor something like that
21:11rhg135Good to know
21:12justin_smithit might have to be clojure.main -e '(do (require 'clojure.tools.nrepl.server) ...))'
21:50justin_smithrhg135: wow - I only include the first try because I am amazed it only took me two tries :) https://www.refheap.com/108658
21:50justin_smithso it's not too tough to start an nrepl server without lein if you know where the jars are
21:50justin_smith(and the magic syntax)
21:59rhg135that hostname...
22:00rhg135alow that's considerably more than just lein repl :P
22:00justin_smithrhg135: the model name is "bonobo"
22:00justin_smithrhg135: it's more to type, if you were to type it by hand
22:01justin_smithalso, you can specify a port, and I assume you would want to do so
22:01rhg135ah, that's much more logical then
22:05rhg135oh, but I want to have an a repl to use just because the fireplace one isn't that great
22:05justin_smithlein repl :connect
22:06rhg135right
22:06justin_smithconnects to an nrepl that is already running, if you need that
22:06rhg135I type faster than I think
22:17rhg135how can I check if a substring is in a string?
22:18gfredericks(.contains "Hello, world!" ", w")
22:19gfredericks,(.contains "Hello, world!" ", w")
22:19clojurebottrue
22:19rhg135ah, thans, I'm relatively unfamiliar with java
22:31gfredericksjavadocs are pretty informative
22:31gfredericksi.e.:
22:31gfredericks$google java 8 String
22:31lazybot[String (Java Platform SE 8 ) - Oracle Documentation] https://docs.oracle.com/javase/8/docs/api/java/lang/String.html
23:20jsonp__http://stackoverflow.com/questions/26386766/check-if-string-contains-substring-in-clojure
23:20jsonp__(re-find #", w" "Hello, world!")
23:20rhg135these are arbitrary strings
23:20jsonp__but Java string is simpler
23:22rhg135till I don't use java
23:22rhg135but for now it wors
23:23jsonp__yeah, re-find is just regex
23:24rhg135unfortunately the way to quote a string for a pattern is not universal
23:55TEttingerrhg135: there's totally a universal way to quote a string for a pattern. it is hideous though
23:58TEttinger,(let [s "[^[][['+\ufeff\\"] (->> s (map (comp (partial format "\\u%04x") int)) (apply str))
23:58clojurebot#<RuntimeException java.lang.RuntimeException: EOF while reading>
23:58TEttinger,(let [s "[^[][['+\ufeff\\"] (->> s (map (comp (partial format "\\u%04x") int)) (apply str)))
23:58clojurebot"\\u005b\\u005e\\u005b\\u005d\\u005b\\u005b\\u0027\\u002b\\ufeff\\u005c"
23:58TEttinger,(let [s "[^[][['+\ufeff\\"] (->> s (map (comp (partial format "\\u%04x") int)) (apply str) (re-pattern)))
23:58clojurebot#"\u005b\u005e\u005b\u005d\u005b\u005b\u0027\u002b\ufeff\u005c"