#clojure logs

2015-12-31

07:21lokienIs if in an if acceptable?
08:29favetelinguiswhat is the easy way to make two numbers 123 456.2 into one number 123456.2
08:34MJB47,(read-string (str 123 456.2)) ; favetelinguis
08:34clojurebot123456.2
09:27favetelinguis,(+ 1 2)
09:27clojurebot3
11:42justin_smith,(* 84 24) ; TIL it's the hear for default TTY resolution
11:42clojurebot2016
11:42justin_smitherr
11:42justin_smithyeah
11:42justin_smitherr wait, I fucked that up, it's 84x24 is my new years resolution
11:42justin_smithyeah that's the ticket
14:28zactsI just got a fresh copy of new Joy of Clojure by Manning Press in the mail from a friend who ordered it when it was a MEAP
14:29zactsI can't wait to read it
14:34justin_smithit's a good book
14:40dhz_ready for new year :D http://s16.postimg.org/xhogpbk1v/image.jpg http://s23.postimg.org/hdi9oiwex/image.jpg
15:09amalloyjustin_smith: isn't 80x24 the standard anyway?
15:10justin_smithamalloy: yes, that was part of the problem
15:10justin_smithjust one of the ways I butchered that joke
15:43nwallaceHey everybody. I'm having an issue trying to learn Om/Next... I can't seem to read any application state in a new component I've defined. I can read state just fine in the root component that renders the whole app, but in a new sub-component, I tried to use the same code to read state into the subcomponent and it's not working. If anyone's interested in helping, please message me :)
16:00chouserWhat in the world am I supposed to do when boot keeps saying "Implicit target dir is deprecated,"?
16:01chouserI'm just following the readme, but the tool is yelling at me. :-(
16:11amalloychouser: from a quick look at the boot source: try setting :target-path to "target"? i haven't used boot so i don't know how you would do that, but it is looking in the boot environment for a thing called :target-path before issuing that warning
16:12chouseramalloy: Thanks. I've tried that. It also says I should use the 'target' task, and I'm doing that now too.
16:13chouserSo far, the only way I can get it to stop complaining is to also set BOOT_EMIT_TARGET=no as it suggests.
16:13chouserMaybe I have to both set the target and also explicitly tell it to stop warning??
16:15amalloy*shrug* no help from me, i'm afraid
16:15chouserthanks for looking. :-)
16:15chouserI don't know why I'm trying boot now, when I'm really supposed to be trying cljs+node.js
16:16amalloy2016 resolution: try the fun things instead of the right things
16:19chouserI like it
16:21chouserI'm gonna put a raspberry pi running node.js into a scale sailboat and try to control it via wifi from a phone. That sounds more fun that right, don't you think?
16:22justin_smiththat sounds awesome
16:23chouserwell, we'll see how far I get before I give up. :-P
16:23justin_smithalso, I've had decent luck running a clojure jar on my raspi. not lein or anything, just a built jar starting up to a repl. It leaves plenty of free heap space, and starts in a semi-reasonable period of time with the jvm that ships on the pi.
16:23justin_smithwell, in the default pi2 image that is
16:24chouserjustin_smith: Hm, good to know. I think I'll pursue node.js first, but it's good to know that standard clojure might be an option too.
17:16featheredtoasthey guys, happy clojuring over my winter break! is there anyone here who can explain the cryptic syntax in the core.logic tutorial here? https://github.com/swannodette/logic-tutorial/blob/master/src/logic_tutorial/tut3.clj#L7
17:29turbofailfeatheredtoast: are you specifically curious about that particular line?
17:31featheredtoastturbofail: syntax/symbols mostly. I'm unfamiliar with the ?r and '.' within a vector
17:31turbofailwell '.' within a vector doesn't really mean anything, that's a syntax borrowed from scheme
17:32turbofailin this context it means "match the rest of this sequence," kind of like how you'd use & in an argument vector
17:33turbofail?r is just a logic variable that we're binding to the rest of the sequence
17:33featheredtoastooh, gotcha. Thanks! that's what I kinda assumed, but the docs on core.logic don't seem to be fully fleshed out
17:33dnolenturbofail: `defne` gives you Prolog style unification on fn arguments
17:33dnolenfeatheredtoast: ^
17:34featheredtoastthanks guys
17:35dnolenit just sugar to remove tedious conde writing
18:01domokatowhat's the simplest way to convert a boolean into number 0 or 1, and back again?
18:03justin_smith(map {0 false 1 true} [1 0 1 1 1 0 0 1])
18:03justin_smith,(map {0 false 1 true} [1 0 1 1 1 0 0 1])
18:03clojurebot(true false true true true ...)
18:03MJB47 cant you do
18:03justin_smith,(map {false 0 true 1} [true false false true false true true true])
18:03MJB47,(boolean 0)
18:03clojurebot(1 0 0 1 0 ...)
18:03clojurebottrue
18:03MJB47,(boolean 1)
18:03clojurebottrue
18:03MJB47nvm
18:03justin_smithMJB47: zeroes and ones are both true
18:03MJB47yer i just remembered
18:04AimHereAre you sure that the only truthy value you want is 1?
18:04justin_smithAimHere: good point
18:05justin_smith#({0 false} % true) is also an option
18:05justin_smith,(map (complement zero?) [1 0 1 0 1 1 1 0 0])
18:05clojurebot(true false true false true ...)
18:05justin_smith(complement zero?) feels clever
18:06domokatojustin_smith: it does!
18:06domokatoi may just use the first one. seems clearest
18:06domokatothx!
18:08tolstoyLament for the venerable if experssion.... ;) (map #(if (zero? %) false true) [1 0 1 1 0 0])
18:08justin_smithtolstoy: but it's so verbose!
18:09justin_smithtolstoy: and that's identical to (complement zero?)
18:09tolstoyik, thx. ;)
18:09domokatonow i wonder which is faster, the map or the complement zero?
18:09justin_smithdomokato: I know a good way to check (checking...)
18:13tolstoy,(map #(condp = 1 true 0 false) [1 0 1])
18:13clojurebot#<ArityException clojure.lang.ArityException: Wrong number of args (1) passed to: sandbox/eval25/fn--26>
18:13justin_smithtolstoy: needs a % in there
18:13tolstoyYeah, I always screw up condp.
18:13tolstoy,(map #(condp = % 1 true 0 false) [1 0 1])
18:14clojurebot(true false true)
18:14tolstoyI like the if better.
18:14tolstoy,(map #(get {1 true 0 false} %) [1 0 1])
18:14clojurebot(true false true)
18:15justin_smithtolstoy: that's silly
18:15justin_smith#(get {1 true 0 false} %) is just {1 true 0 false}
18:16justin_smithI mean sure, they are not identical, but they don't differ in a way that matters here
18:16tolstoy,(map {1 true 2 false} [1 0 1 1])
18:16clojurebot(true nil true true)
18:17tolstoy,(map {1 true 0 false} [1 0 1 1])
18:17clojurebot(true false true true)
18:17tolstoyNeat. ;)
18:22justin_smithOK, just spent some time messing around - all the options took 9.x ns
18:22justin_smithexcept the map literal, which only took 7.x
18:22justin_smithbut, if I used a def, then used that instead of a literal, it went up to 9.x
18:22justin_smithweird!
18:22neoncontrails(justin_smith: map literal... you mean tolstoy's suggestion, right?
18:23justin_smithI mean my first suggestion
18:23domokatothat works out. turns out i'm using a literal, not a def
18:23justin_smith{0 false 1 true} that's a map literal
18:23neoncontrailsheh apparently all it takes is 15 minutes of casually coding in Clojure to make me go left-parenthesis mad
18:24domokatojustin_smith: thx dude
18:25neoncontrailsjustin_smith: that makes sense to me actually. I was curious how complement could compete with a literal mapping, considering the complement solution would also work for non-binary numbers
18:26justin_smithyeah, the (complement zero?) one performed about the same
18:26justin_smiththey were all pretty close
18:30amalloythe main overhead is probably allocating all the cons cells
18:31amalloyhow you convert int->bool got lost in the noise
18:31justin_smithtrue
18:36justin_smithamalloy: d'oh - criterium doesn't doall on top level laziness :P
18:43justin_smiththe numbers are in! if was fastest https://gist.github.com/noisesmith/b3ea6e44615613a0d458
18:44tolstoy"if" is fastest? Heh. But it's so ... mundane!
18:45justin_smith:)
18:47neoncontrailsjustin_smith: is the standard 'time' library flawed?
18:47neoncontrailsI noticed you're using a third-party extension
18:48justin_smithneoncontrails: it doesn't reliably make hotspot kick in
18:48justin_smithcriterium is much more reliable in its measurements
18:48justin_smithhttps://github.com/hugoduncan/criterium
18:49neoncontrailsInteresting. I had no idea benchmarking on the JVM was fraught with peril
18:50justin_smithneoncontrails: the automatic runtime optimization thing means getting a good measurement is tricky
18:51justin_smithalso, regardless of platform, statistical analysis of multiple runs is much more informative than a strict average
18:51neoncontrailsI see. Both good points.
18:51rhg135is assuming hotspot always optimizes a good idea?
18:51justin_smithgiven that your computer is probably doing more than just running the benchmarks
18:51justin_smithrhg135: it is better at optimizing some things than others, there are flags to turn it on or off, and flags to make it operate verbosely
18:52justin_smithrhg135: by default "lein repl" will disable hotspot, for example
18:53rhg135I thought hotspot will prioritize "hot" code such as loops which means most code is not in practice
18:54justin_smithrhg135: it is expensive to generate the optimized version, so it only optimizes things that get run frequently
18:55justin_smithrhg135: and then, it can only optimize so much, depending on the structure of your code - can it inline anything? can it unbox anything? etc. many "dynamic" things that allow runtime redefinition prevent optimization (because it can't safely do the transformation and ensure 100% correctness)
18:56justin_smithrhg135: I found a really awesome video about what hotspot can and cannot inline, let me see if I can find it again
18:56rhg135yeah. I guees that'- a problem with microbenchmarks
18:57rhg135it'- always better to see what is actually happening
18:57justin_smithyes, microbenchmarks can answer micro-questions, but in a real app most of your work is finding the bottleneck where the optimization even helps
18:58justin_smithrhg135: https://www.youtube.com/watch?v=0Yud4Q2HEz4
19:03rhg135thx mate
21:16ben_vulpesis there a slick way to de-namespace keywords in a map?
21:16justin_smithben_vulpes: (comp keyword name)
21:16justin_smithI mean that and your typical map-keys f of course
21:16ben_vulpesjustin_smith: quickest hand in the west
21:17ben_vulpes*pow* *pow*
21:17ben_vulpesthanks, justin_smith
22:24justin_smithTIL 2016 is the number of edges of a fully connected undirected graph with 64 vertices.
22:24TEttingerhuh!
22:25TEttingerwhat about 65 vertices?
22:25TEttingerwhen's the next year :)
22:25justin_smithn(n-1)/2
22:25TEttingeroh that's that one
22:26TEttinger,(/ (* 65 64) 2)
22:26clojurebot2080
22:26TEttingeroh, maybe in some of our lifetimes
22:26justin_smith,(defn uni-graph-edges [n] (* n (dec n) (/ n 2))
22:26clojurebot#<RuntimeException java.lang.RuntimeException: EOF while reading>
22:26justin_smith,(defn uni-graph-edges [n] (* n (dec n) (/ n 2)))
22:26clojurebot#'sandbox/uni-graph-edges
22:26TEttingerI'd be 92...
22:26justin_smith(uni-graph-edges 64)
22:26justin_smith,(uni-graph-edges 64)
22:26clojurebot129024
22:26justin_smitherr...
22:26justin_smithoops!
22:27justin_smith,(defn uni-graph-edges [n] (* n (dec n) 0.5))
22:27clojurebot#'sandbox/uni-graph-edges
22:27justin_smith,(uni-graph-edges 64)
22:27clojurebot2016.0
22:27justin_smith,(uni-graph-edges 63)
22:27clojurebot1953.0
22:27justin_smithfirst one since '53
22:28justin_smith,(uni-graph-edges 65)
22:28clojurebot2080.0
22:28justin_smithyeah, it'll be a while
22:29justin_smith,2r11111100000
22:29clojurebot2016
22:29justin_smith!
22:32justin_smith,2r11111011111 ; last year was a palindrome
22:32clojurebot2015
22:32justin_smith,2r11111111111 ; next one
22:32clojurebot2047
22:32MJB47now that youve pointed that out
22:32MJB47you have to make an algorithm
22:32justin_smithoooh
22:32MJB47to find all of htem
22:32MJB47lazily
22:33justin_smithfun
22:33MJB47happy new year!
22:38justin_smith,(.reverse 42)
22:38clojurebot#error {\n :cause "No matching field found: reverse for class java.lang.Long"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "No matching field found: reverse for class java.lang.Long"\n :at [clojure.lang.Reflector getInstanceField "Reflector.java" 271]}]\n :trace\n [[clojure.lang.Reflector getInstanceField "Reflector.java" 271]\n [clojure.lang.Reflector invokeNoArgInstanceMem...
22:38justin_smith,(Long/reverse 42)
22:38clojurebot6052837899185946624
22:38justin_smithhmm...
22:40justin_smith,(bit-shift-right (Long/reverse 42) 60)
22:40clojurebot5
22:40justin_smith,(bit-shift-right (Long/reverse 5) 60)
22:40clojurebot-6
22:40justin_smith:P
22:41justin_smithsign extension!
22:42amalloydidn't something like logical-bit-shift-right get added?
22:43justin_smith,(unsigned-bit-shift-right (Long/reverse 5) 60)
22:43clojurebot10
22:43justin_smithhmm
22:43justin_smithso I'm still not doing it right, but that's the ticket, thanks
22:45justin_smith(iterate #(unsigned-bit-shift-right (Long/reverse %) 58) 42)
22:45justin_smith,(iterate #(unsigned-bit-shift-right (Long/reverse %) 58) 42)
22:45clojurebot(42 21 42 21 42 ...)
22:46justin_smith,(iterate #(unsigned-bit-shift-right (Long/reverse %) 53) 2015)
22:46clojurebot(2015 2015 2015 2015 2015 ...)
22:46TEttingerhttp://clojuredocs.org/clojure.core/unsigned-bit-shift-right
22:46TEttingerah you found it
22:46justin_smithso now I just need to derive the magic number
22:46justin_smithfor the bit shift
22:50justin_smith,(defn bit-palindrome? [n] (= n (unsigned-bit-shift-right (Long/reverse n) (Long/numberOfLeadingZeros n))))
22:50clojurebot#'sandbox/bit-palindrome?
22:50justin_smith,(bit-palindrome? 2015)
22:50clojurebottrue
22:50justin_smith,(bit-palindrome? 2047)
22:50clojurebottrue
22:50justin_smith,(bit-palindrome? 2016)
22:51clojurebotfalse
22:51justin_smithMJB47: did it!
22:51MJB47not exactly what i asked, but good enough
22:51MJB47congrats
22:51MJB47you got 1 internet point
22:51MJB47:)
22:51justin_smith,(filter bit-palindrome? range)
22:51clojurebot#<IllegalArgumentException java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.core$range>
22:51justin_smith,(filter bit-palindrome? (range)) ; OK fine
22:51clojurebot(0 1 3 5 7 ...)
22:52MJB47:P
22:52kenrestivoi'm trying to combine lein do, lein update-in, and lein with-profile, and not having any luck
22:52TEttinger,31r231
22:52clojurebot2016
22:52kenrestivowhat's the right Magickal Incantation to have a do, update-in, and with-profile coexisting peacefully?
22:53justin_smithkenrestivo: maybe it would help if you were trying to trampoline also
22:55justin_smithTEttinger: here's a fun one from r/math: (6!! - 6) 6!!
22:55kenrestivo nope, that'd just make it more complex
22:56kenrestivoi'm gettign EOF while reading string
22:56kenrestivoi have to do these things sorry. i need lean profile, i need to run a compile task, and i need to inject the keystore password via update-in
22:56kenrestivosince that ain't going in my project.clj
22:58justin_smithkenrestivo: are you sure the keystore password is needed in order to compile - can't it be factored out of that?
22:59kenrestivonope
22:59kenrestivohmm, i found a way around the eOF complaint
22:59kenrestivo\\"password\\"
23:01TEttingerjustin_smith: did I do it right?
23:01TEttingerhttps://www.refheap.com/113279
23:02justin_smithI'm guessing no!
23:04kenrestivothogh it mangled the password, so that didn't help :( ugh, nevermind. 10 more minutes with this then i'll get bored and move on
23:05justin_smithTEttinger: I'm thinking I misread the thing... https://www.reddit.com/r/math/comments/3yukgr/answer_2016/cygy3nm
23:05TEttingeryeah I screwed up slightly https://www.refheap.com/113280
23:05justin_smithTEttinger: or perhaps I am gullible
23:06justin_smithTEttinger: maybe OP of the formula got an overflow and didn't realize?
23:06TEttingeror maybe !! is choose
23:06TEttingerit's in combinatorics
23:07justin_smithAH
23:07justin_smiththat makes a lot more sense, thanks
23:07justin_smithI have not seen that notation for choose before though
23:09TEttingerdouble factorial
23:09TEttingerhttp://reference.wolfram.com/language/ref/Factorial2.html
23:10kenrestivosolveded: lein with-profile lean do update-in :android assoc :keypass "\"pass\"" :storepass "\"pass\"" -- droid apk
23:10kenrestivo\"\"\\ok?\""\"?
23:10justin_smithkenrestivo: "\"pass\"" could be '"pass"'
23:10kenrestivoaye, that'd work too, thanks
23:11justin_smithkenrestivo: the command will still work, but can start faster, if you insert "trampoline" before with-profile
23:11justin_smithsorry about the bad joke though
23:12justin_smith,(defn bit-palindrome? [n] (= n (unsigned-bit-shift-right (Long/reverse n) (Long/numberOfLeadingZeros n))))
23:12clojurebot#'sandbox/bit-palindrome?
23:12justin_smith,(filter bit-palindrome? (range 2047 2050))
23:12clojurebot(2047 2049)
23:12justin_smithcool
23:14TEttinger,(let [!! (reduce * (range 2 7 2))] (* (- !! 6) !!))
23:14clojurebot2016
23:15justin_smith,[(Long/toString 2047, 2) (Long/toString 2049, 2)] ; d'oh, of course
23:15clojurebot["11111111111" "100000000001"]
23:17TEttinger,(defn radit-palindrome [n radix] (= (seq (Long/toString n radix)) (reverse (Long/toString n radix))))
23:17clojurebot#'sandbox/radit-palindrome
23:17TEttinger,(radit-palindrome 3r222 3)
23:17clojurebottrue
23:17TEttinger,(radit-palindrome 3r220 3)
23:17clojurebotfalse
23:17justin_smithnice!
23:17TEttinger,(radit-palindrome 3rZZZ 36)
23:17clojurebot#<NumberFormatException java.lang.NumberFormatException: For input string: "ZZZ">
23:17TEttinger,(radit-palindrome 36rZZZ 36)
23:17clojurebottrue
23:24justin_smithTEttinger: if it wasn't clear, I intentionally used the string rep version for the binary palindrome one, because I knew there had to be an elegant way to do it directly with bit ops
23:24justin_smith*intentionally did not use
23:24justin_smithbut the general version is of course a lot easier with the strings
23:31TEttingeroh yeah
23:31TEttingerI don't know how you'd do it easily with non-binary numbers
23:32justin_smithreplace bit-and and bit-shift-right with ? and logbaseN
23:54ben_vulpesdoes anyone have any tips on destructuring maps that use strings as their keys?
23:54justin_smithben_vulpes: :strs
23:54amalloyben_vulpes: do you know what {:keys [x]} is shorthand for?
23:54ben_vulpesamalloy: no sir
23:55amalloyit is short for {x :x}
23:55justin_smith,(let [{:strs [a b c]} {"a" 1 "b" 2 "c" 3}] (+ a b c))
23:55amalloyso, you could write {x "x"}
23:55clojurebot6
23:55amalloyas justin_smith shows, there is shorthand for that too
23:55ben_vulpesamalloy well yes, in that sense i am rather familiar with it.
23:55ben_vulpesthe keys/strs switch is precisely the thing i b'leev.
23:55ben_vulpeswhere is that documented?
23:56justin_smithben_vulpes: with the docs for destrucuring
23:57justin_smithben_vulpes: http://clojure.org/special_forms#Special Forms--Binding Forms (Destructuring)
23:57justin_smithoh man somebody should have put %20s in that string
23:57justin_smiththose docs don't mention :syms or :strs though
23:58justin_smithoh, wait, yes it does
23:59justin_smithben_vulpes: there's even a link to those docs in the doc string for let