#clojure log - Aug 23 2015

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

1:18 kenrestivo: i'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

1:18 any hacks for reading such a file in?

1:19 justin_smith: kenrestivo: #<...> is the format for objects that are not readable

1:19 kenrestivo: recent clojure versions print #inst or #obj etc. instead

1:19 ,(java.util.Date.)

1:19 clojurebot: #inst "2015-08-23T05:20:02.097-00:00"

1:20 justin_smith: ,(java.util.HashMap.)

1:20 clojurebot: {}

1:20 justin_smith: err...

1:20 ,(Object.)

1:20 clojurebot: #object[java.lang.Object 0x298607bc "java.lang.Object@298607bc"]

1:20 kenrestivo: yeah, i know it's bad. i'm just wondering what to do with the file.

1:20 justin_smith: you can actually make a reader for that at least

1:20 kenrestivo: this looks promising: https://gist.github.com/ragnard/4738185

1:20 justin_smith: kenrestivo: fix it with sed?

1:21 kenrestivo: true, the sed brute force might be simplest. thanks

1:22 justin_smith: or even clojure.string/replace come to think of it

1:23 kenrestivo: replace would work, i'm slurping it in, can do that before calling the reader

1:25 (-> f slurp (string/replace #"#<DateTime (.+?)>" "#inst \"$1\"") (clojure.edn/read-string)) ;; works

1:26 justin_smith: wow, how retro, it's like perl or something :)

1:26 hmm

1:26 ,(str (java.util.Date.))

1:26 clojurebot: "Sun Aug 23 05:26:37 GMT 2015"

1:26 justin_smith: ,(str [(java.util.Date.)])

1:26 clojurebot: "[#inst \"2015-08-23T05:27:01.913-00:00\"]"

7:15 hyPiRion: hmm

7:15 ,(pr (java.util.Date.))

7:15 clojurebot: #inst "2015-08-23T11:15:27.806-00:00"

7:57 lunaticleo: ,(java.util.Date.)

7:57 clojurebot: #inst "2015-08-23T11:57:20.530-00:00"

9:39 xtrntr: hi, noob here

9:39 i don't think my terminal is making any progress on lein cljsbuild auto

9:39 i always have to use lein cljsbuild once

9:40 i can't understand why, is it a common occurence?

9:40 plus compiling takes a super long time

9:50 gfredericks: xtrntr: it might be that it's using cached versions; I'd try changing/saving a file and see if that makes it do something

9:54 oracle`:

9:54 ii

9:54 /

9:54 hi

9:56 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.

9:57 does re-com work with mobile device?

9:58 lokien_: Hey, does anyone here use spacemacs?

9:59 oracle`: yes, I am using it. super good

10:01 lokien_: I have to invoke some command through m+x every time I open it

10:01 Is there a better way of doing it?

10:01 Like, add this command to startup

10:06 oracle`: you can put it to .spacemacs file

10:09 lokien_: oracle`: can you show me an example on pastebin or something?

10:25 spacepluk: hi, is there any portable timer library?

10:45 novak`: 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:40 justin_smith: the two obvious options are to change your output locations or to change your classpath

13:05 ely-se: Is 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:11 gfredericks: ely-se: I think that would be pretty fancy

13:11 especially if you expect the kind of structure sharing that the persistent data structures have

13:12 it would likely take a lot of time/computation/memory to do the serialization

13:12 justin_smith: gfredericks: 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:13 gfredericks: unless you wanted to hack into the persistent data structures and mess with the internal nodes

13:14 I assume that's physically possible on the jvm but don't know for sure

13:19 ely-se: I'll just go with edn now and see if it becomes a problem. :p

13:19 time for a shower

13:35 justin_smith: gfredericks: 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:46 pseudonymous: If 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:48 justin_smith: pseudonymous: one easy way to do it is a core.async go-loop

13:48 pseudonymous: justin_smith: I see - I'll go look in that direction, then. Thanks :)

13:48 justin_smith: you could also consider a ScheduledExecutorService

13:49 there's a lib from overtone that wraps ScheduledExecutorService called at-at

13:49 pseudonymous: Oh, sort of a cron-job for Clojure. Interesting

13:50 justin_smith: yeah, ScheduledExecutorService is like a much more flexible cron

13:51 pseudonymous: Hehe. 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:52 justin_smith: haha

13:54 richy: ciao

13:54 !list

13:55 ciao

13:57 ely-se: ciaojure

13:58 gfredericks: justin_smith: yeah, walking the internal nodes

14:19 kanja: I'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:26 ely-se: why do < and > and friends not use Comparable<T> interface?

14:26 justin_smith: because they can be faster if they specialize for numbers

14:26 ely-se: great

14:38 jonathanj: (apologies if i've asked this before, i can never quite remember what i'm looking for)

14:39 how do i do an "unzip": ['(a b) '(c d) '(e f)] => ['(a c e) '(b d f)]

14:40 justin_smith: ,(apply map list '[[a b] [c d] [e f]])

14:40 clojurebot: ((a c e) (b d f))

14:42 jonathanj: ah, map takes varargs

14:42 thank you

14:42 justin_smith: np

14:44 jonathanj: the cool thing it is a two way transform

14:44 ,(iterate #(apply map list %) '[[a b c] [d e f]])

14:44 clojurebot: ([[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:44 jonathanj: :)

14:45 justin_smith: it will keep repeating the two rotations over and over

14:45 jonathanj: my only gripe is that (apply map list %) is not very obvious to a reader

14:45 justin_smith: it's definitely an idiom though

14:46 and if you go through step by step you can figure out what it would do - it's only a few functions

14:50 jonathanj: yeah, it's just unfortunately a bit wordy

14:58 gfredericks: (def zip (partial apply map list)) (def unzip zip)

15:14 tmtwd: how do I do this example with threading? http://pastebin.com/tEMXfMAq

15:17 oddcully: (-> m :profile :name)

15:18 tmtwd: thanks

15:34 what is the point of get-in when we can just use shorthand (:name (m :profile)) instead of (get-in m [:profile :name])?

15:34 justin_smith: tmtwd: get-in works for keys that are not keywords

15:35 ,(get-in {"a" [1 2 3]} ["a" 1])

15:35 clojurebot: 2

15:36 justin_smith: tmtwd: also, sinec [:profile :name] is a normal data structure, I can construct it at runtime without using eval

15:45 tmtwd: justin_smith, huh?

15:46 justin_smith: tmtwd: 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:48 TEttinger: (inc justin_smith)

15:48 lazybot: ⇒ 286

15:48 TEttinger: I hadn't thought about using code to generate get-in vectors

15:48 justin_smith: it's pretty powerful, and sometimes even useful

16:25 rocasam_: hi all

16:26 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:27 gfredericks: probably not if I had to guess

16:27 rhg135: not via raw IRC

16:28 rocasam_: hmmm pitty, but not a disaster

16:28 ely-se: run a server that acts as an IRC client and connect to it from both machines :P

16:28 rhg135: you can set up a bouncer, a persistent weechat, or look to irccloud

16:29 I personally do the first two, I run a shared znc with a weechat for myself

16:29 ely-se: for bonus points, reinvent the wheel by writing said server in Clojure

16:30 rocasam_: I have irccloud in my Android

16:31 I am logged in there, but then the Hexchat client on my pc tells me the nick is already in use.

16:31 sorry am a total newby - I havent been in irc chat since the nineties!

16:31 rhg135: there's a web client for it

16:32 that'll connect as your android

16:32 rocasam_: irccloud webclient?

16:32 rhg135: yeah

16:32 rocasam_: Ill check it out

16:34 works! thanks rgh135 :-)))

16:35 rhg135: np

16:35 I actually used irccloud long ago before I bought my rpi

16:35 ely-se: I want to do temporal pattern recognition in Clojure.

16:36 rocasam: Seems to be working really well.

16:38 What do you mean with rpi rhg135

16:39 rhg135: rocasam: I have a small ARM computer (called a raspberry pi) on which I run a znc server

16:40 rocasam: I get it, not the znc part, seems terribly difficult but fun :-)

16:41 rhg135: I only run the znc for benefit of others, I myself use weechat inside tmux

16:46 rocasam: Great!

16:52 tmtwd: http://pastebin.com/pTrzrUVt how do I have default values to replace nil values with threading?

16:53 rhg135: (or (some-> seed stuff) default)

17:02 oddcully: (-> m (get-in [:profile :address :zip-code] "no zip code!")) ;P

17:02 what's wrong with get-in?

17:02 rhg135: or that

17:02 oddcully: that's silly

17:07 tmtwd: oddcully, thanks

17:08 oddcully: tmtwd: i put that up in jest. i find that hardly an improvement

17:08 tmtwd: eh

17:08 I misread it initially

17:08 maybe you can't do it with threading

17:09 oddcully: the version of rhg135 is nice, if you want to have -> in your code

17:10 rhg135: threading for map access, seems overkill

17:11 but answering the question

17:13 ely-se: not sure why she doesn't want to tell her colleagues about it

17:13 oops, wrong channel

17:16 oddcully: yet i have used or/some-> in some recent code... now i wonder, why i have not used get-in

17:16 rhg135: not plain map access?

17:16 if you require post-processing it seems decent

17:20 oddcully: nope. i tend to use cond-> for that. i assumed, that get-in nil would not work. but it does

17:21 rhg135: -> is not too bad as you can just macroexpand it to see what it would do

17:22 a custom function loop otoh is much worse

18:20 http://www.rhg135.com/posts/2015-08-23-var-or-fn.html I remember stumbling over this one

18:49 tmtwd: does anyone know off hand what the nil is in om where (dom/li nil text)

18:53 justin_smith: tmtwd: empty properties for the li?

19:03 monsta: Good night, I have a question, how specify the port where i want the repl to connect in the project.clj?

19:05 hyPiRion: monsta: ":repl-options {:port 4001}" for example

19:05 justin_smith: monsta: https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L354 the relevant line in the example project.clj

19:06 monsta: justin_smith: Thank, I feel so stupid now

19:37 camm_v222: Hi, 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:52 AWizzArd: ,(.-length (byte-array 5)) ;; shouldn’t this return 5?

19:53 clojurebot: #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:53 justin_smith: ,(count (byte-array 5))

19:53 clojurebot: 5

19:53 AWizzArd: Sure, but I suppose that .length would be faster.

19:53 justin_smith: it would be if the class had such a field I guess?

19:53 ,(.length (byte-array 5))

19:53 clojurebot: #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:54 AWizzArd: At least in Java there is a length property for Arrays.

19:54 justin_smith: AWizzArd: also for collections that store their own size, you can count on count to access that directly and not count item by item

19:54 AWizzArd: oh right, arrays don't have methods, so it's a static method on the Array class

19:54 ,(Array/length (byte-array 5)) ; something like this

19:54 clojurebot: #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:55 AWizzArd: ,(alength (byte-array 5))

19:55 clojurebot: 5

19:55 justin_smith: there we go

19:55 AWizzArd: Okay good, thx.

19:55 justin_smith: but you can count on count to get the result in a fast way

19:55 if it is possible

19:56 AWizzArd: Yeah, 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:56 Otherwise I wouldn’t care and simply call `count`.

20:22 justin_smith: AWizzArd: woah, acording to criterium, count is quite a bit faster

20:23 AWizzArd: https://www.refheap.com/108656

20:32 AWizzArd: justin_smith: Oh, this is certainly unexpected.

20:32 justin_smith: although… in the first case you bench the creation of the array itself too.

20:32 justin_smith: AWizzArd: no, see that I cancel it

20:33 AWizzArd: justin_smith: ah k

20:33 Well, surprising indeed. But good, that way I am totally forced to use count.

20:33 justin_smith: AWizzArd: update - its fastest with alength + hint, edited https://www.refheap.com/108656

20:34 AWizzArd: so if you are warning on reflection and using alength, that seems the best so far (now trying with count + hint)

20:34 AWizzArd: the diff. in performance between the three is kind of crazy

20:34 AWizzArd: justin_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:34 justin_smith: AWizzArd: hints do not work that way

20:34 since any def can change a var at any time

20:35 there are no implicit hints on def

20:35 AWizzArd: I mean that (alength (byte-array 5)) might work without reflection.

20:35 justin_smith: AWizzArd: since perf is so important to you, I'd definitely have reflection and boxing warnings turned on

20:36 AWizzArd: justin_smith: I always have them in my project.clj template activated.

20:36 justin_smith: AWizzArd: sure, that would, hell if the compiler weren't so dumb it could sub in 5 at compile time :P

20:36 AWizzArd: (-:

20:36 justin_smith: thanks for this test though, it confirms my idea that alength could save time.

20:37 justin_smith: also, criterium is totally worth adding to your profiles.clj / user

20:37 always handy

20:37 AWizzArd: I have it in there too. I agree that it is an excellent default development tool.

20:37 justin_smith: yeah, so hinting doesn't affect "count" at all, but it makes a huge difference with alength

20:38 AWizzArd: Yes, I guess that count is doing the dispatching, so I supposed it would be slower.

20:38 justin_smith: https://www.refheap.com/108656 one more update for the count / hint combo - showing basically no difference

20:39 AWizzArd: A type hint should in no case improve the performance of calling a clojure function.

20:39 The exception are the array functions – and those are probably not clojure functions, though they look that way, as the leading . is missing.

20:41 justin_smith: ,(source alength)

20:41 clojurebot: Source not found\n

20:41 justin_smith: $source alength

20:41 lazybot: alength is http://is.gd/Xb2FWl

20:41 justin_smith: anyway, it's a function that just does an interop call

20:42 with a handy inline annotation

20:42 AWizzArd: Indeed.

20:42 Makes sense, as Rich knew that array users probably care for efficiency.

20:44 Btw, 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:44 Something similar to this auto compiler for cljs.

20:45 justin_smith: the 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:45 AWizzArd: not that I know of...

20:46 Bronsa: 02:39:19 <AWizzArd> A type hint should in no case improve the performance of calling a clojure function.

20:46 except when those functions are inlineable

20:46 or macros

20:46 justin_smith: (inc Bronsa)

20:46 lazybot: ⇒ 119

20:46 justin_smith: thanks for clearing that up

20:47 AWizzArd: Bronsa: so this seems to be the case with the array fns.

20:47 Bronsa: yup

20:47 AWizzArd: Is inlineability the criterium, or is it inlineability plus they must be calling into Java?

20:48 Bronsa: obviously interop must play a part

20:48 AWizzArd: si

20:48 Bronsa: but deftype field access is also interop, and Java isn't involved technically

20:50 why the hell doesn't byte-array have a ^bytes type hinth though

20:50 ah it doesn't need one

20:50 justin_smith: Bronsa: I thought it was because I was using a var that the hint ended up being needed

20:50 Bronsa: yeah

20:51 I wish type hinting stuff like (def foo "bar") wasn't needed

20:51 but I guess it'd impact dynamicity

20:52 (I also wish vars used a different keyword for tagging their value rather than overloading :tag but that's another complaint)

20:54 AWizzArd: Bronsa: why doesn’t byte-array need no ^bytes hint?

20:54 Bronsa: it's inlined

20:55 AWizzArd: Bronsa: 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:55 Bronsa: yes

21:00 rhg135: any way to make lein repl outside a project use clojure 1.7? I miss my transducers

21:01 AWizzArd: Bronsa: 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:02 rhg135: never tried it, but can you add Clojure 1.7 to your profiles.clj maybe and see if that changes anything?

21:03 rhg135: nope

21:04 dummy project it is

21:05 or boot

21:09 justin_smith: rhg135: are you tied to using nrepl? otherwise without a project def you can get super fast startup by just calling clojure.jar directly

21:10 rhg135: I am for now, justin_smith. I'm using vim fireplace

21:11 justin_smith: rhg135: you could also invoke `java -cp clojure-1.7.jar:some-nrepl.jar clojure.nrepl/start-server

21:11 or something like that

21:11 rhg135: Good to know

21:12 justin_smith: it might have to be clojure.main -e '(do (require 'clojure.tools.nrepl.server) ...))'

21:50 rhg135: wow - I only include the first try because I am amazed it only took me two tries :) https://www.refheap.com/108658

21:50 so it's not too tough to start an nrepl server without lein if you know where the jars are

21:50 (and the magic syntax)

21:59 rhg135: that hostname...

22:00 alow that's considerably more than just lein repl :P

22:00 justin_smith: rhg135: the model name is "bonobo"

22:00 * rhg135 makes an alias

22:00 justin_smith: rhg135: it's more to type, if you were to type it by hand

22:01 also, you can specify a port, and I assume you would want to do so

22:01 rhg135: ah, that's much more logical then

22:05 oh, but I want to have an a repl to use just because the fireplace one isn't that great

22:05 justin_smith: lein repl :connect

22:06 rhg135: right

22:06 justin_smith: connects to an nrepl that is already running, if you need that

22:06 rhg135: I type faster than I think

22:17 how can I check if a substring is in a string?

22:18 gfredericks: (.contains "Hello, world!" ", w")

22:19 ,(.contains "Hello, world!" ", w")

22:19 clojurebot: true

22:19 rhg135: ah, thans, I'm relatively unfamiliar with java

22:31 gfredericks: javadocs are pretty informative

22:31 i.e.:

22:31 $google java 8 String

22:31 lazybot: [String (Java Platform SE 8 ) - Oracle Documentation] https://docs.oracle.com/javase/8/docs/api/java/lang/String.html

23:20 jsonp__: http://stackoverflow.com/questions/26386766/check-if-string-contains-substring-in-clojure

23:20 (re-find #", w" "Hello, world!")

23:20 rhg135: these are arbitrary strings

23:20 jsonp__: but Java string is simpler

23:22 rhg135: till I don't use java

23:22 but for now it wors

23:23 jsonp__: yeah, re-find is just regex

23:24 rhg135: unfortunately the way to quote a string for a pattern is not universal

23:55 TEttinger: rhg135: there's totally a universal way to quote a string for a pattern. it is hideous though

23:58 ,(let [s "[^[][['+\ufeff\\"] (->> s (map (comp (partial format "\\u%04x") int)) (apply str))

23:58 clojurebot: #<RuntimeException java.lang.RuntimeException: EOF while reading>

23:58 TEttinger: ,(let [s "[^[][['+\ufeff\\"] (->> s (map (comp (partial format "\\u%04x") int)) (apply str)))

23:58 clojurebot: "\\u005b\\u005e\\u005b\\u005d\\u005b\\u005b\\u0027\\u002b\\ufeff\\u005c"

23:58 TEttinger: ,(let [s "[^[][['+\ufeff\\"] (->> s (map (comp (partial format "\\u%04x") int)) (apply str) (re-pattern)))

23:58 clojurebot: #"\u005b\u005e\u005b\u005d\u005b\u005b\u0027\u002b\ufeff\u005c"

Logging service provided by n01se.net