#clojure logs

2014-06-27

00:00dbaschif anything, the point of fnil is to recover from null pointers and avoid a null pointer exception
00:00boltRah I see
00:01boltRI was trying to create an anonymous function for passing to update-in
00:02boltRI think I can just use an if-else
00:02dbaschyou want to throw an exception in the middle of an update?
00:02boltRyeah if a key doesn't already exist in the hashmap
00:05dbaschboltR: update-in will create them if they don't, so you'd have to check
00:07dbasche.g.
00:07dbasch,(update-in {:a {:b 1}} [:a :c] str)
00:07clojurebot{:a {:c "", :b 1}}
00:14boltRdbasch: ah I see
00:14boltRso I need to check the hash before the update-in call
00:19trptcolin,(update-in {:a {:b 1}} [:a :b] #(if % (inc %) (throw (Exception. "this is bad code"))))
00:19clojurebot{:a {:b 2}}
00:19trptcolin,(update-in {:a {:b 1}} [:a :c] #(if % (inc %) (throw (Exception. "this is bad code"))))
00:19clojurebot#<Exception java.lang.Exception: this is bad code>
00:26boltRtrptcolin: why is that considered bad code?
00:29trptcolindon’t mind me, i’ve been watching monad videos
00:30trptcolinit works, just not a use case where i’d typically reach for exceptions
00:33boltRtrptcolin: i just realized i'm not supposed to put the exception in the update-in line
00:33boltRhaha
00:33boltRoh well.. still good to know
00:41ndpHey all, what's the right way to compare keywords in ClojureScript?
00:41ndpRight now I'm using keyword-identical? but it's not working when getting a value from a map to compare against.
00:43ndpAh, never mind - I found the problem as I was copying here. I had an extra ":" floating around.
00:52ttasterisco,(= :k1 :k2)
00:52clojurebotfalse
00:52ttasterisco,(let [x :k1] (= :k1 x))
00:52clojurebottrue
00:53ttasterisco,(doc keyword-identical?)
00:53clojurebotIt's greek to me.
00:55john2xhow do I upgrade my leiningen? I tried `lein upgrade`, but it seems it's intended for projects?
00:56trptcolin`lein upgrade` should work for the normal case. perhaps you have lein installed via a package manager?
00:56trptcolinwhat is the problem you’re seeing?
00:57john2xsorry, got disconnected. trptcolin, you mean me?
00:57ttasteriscoyes
00:58john2x"Couldn't find project.clj, which is needed for upgrade"
00:58ttasteriscohuh
00:58john2xIt does update a bunch of libraries in my .lein/profiles.clj though
00:58john2xbut I want to update to lein 2.4.x (currently on 2.3.4)
00:59ttasteriscoI just updated my lein with lein upgrade
00:59ttasteriscoLeiningen 2.4.2 on Java 1.8.0_05 Java HotSpot(TM) 64-Bit Server VM
01:00john2xstrange.. i installed this via homebrew.. but on brew it's still at 2.3.4.. and I don't want to use HEAD
01:00john2xI guess I should re-install from the github downloads?
01:00ttasteriscohttps://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
01:02trptcolinjohn2x: yeah `lein upgrade` doesn’t work for package managers unless they go in and tweak the script (which nobody does, i don’t think): https://github.com/technomancy/leiningen/issues/1377
01:03john2xthanks. oh and it seems it's at 2.4.2 in homebrew now.. guess I'll just keep on brewin'
01:05ddellacostajohn2x: not sure but I think most folks avoid leiningen via homebrew. YMMV
01:06john2xhmm yeah.. probably would cause more hard-to-diagnose issues someday.
01:23Raynesjohn2x: It's just that leiningen is just a shell script and a jar file.
01:23RaynesSo using a package manager feels strange :P
02:58Klaufirhow can I generate a vec using a function ?
02:58KlaufirI have tried
02:58Klaufir(reduce #(cons (rand 1) %1) [] (range 10))
02:59Klaufirbut this is problematic because #(...) here takes only 1 argument
03:09AimHereKlaufir, what do you mean by 'generate a vec using a function'?
03:11AimHere,((fn [] (vec (range 10))))
03:11clojurebot[0 1 2 3 4 ...]
03:11KlaufirAimHere: call a function n times, then put the n results into a vec
03:11AimHereOh, well that's outwith the functional idiom
03:12KlaufirAimHere: how would you generate a vec of random numbers?
03:12Klaufirgiven by the function 'rand'?
03:13AimHere(vec (take 10 (repeatedly rand)))
03:13AimHere,(vec (take 10 (repeatedly rand)))
03:13clojurebot[0.12962159592537548 0.31180927009168413 0.7594697727309286 0.7412669247226338 0.18135883841833167 ...]
03:13AimHereYou should be thinking in terms of laziness and sequences in Clojure, for that sort of thing
03:14AimHereYou *could* write a reentrant function using atoms or refs as static variables, but it's unidiomatic
03:16KlaufirAimHere: thanks, this looks great
03:38ddellacosta,(clojure-version)
03:38clojureboteval service is offline
03:38ddellacostadamnit
03:38ddellacosta&(clojure-version)
03:38lazybot⇒ "1.4.0"
03:38ddellacosta&(name :/)
03:38lazybotjava.lang.RuntimeException: Invalid token: :/
03:38ddellacosta&(name :-)
03:38lazybot⇒ "-"
03:39ddellacosta&(name (keyword "/"))
03:39lazybot⇒ "/"
03:39ddellacosta&(keyword "/")
03:39lazybot⇒ :/
03:39blur3dHey guys, I’m trying to make a way to visualise data collected in real-time from an Arduino. Basically, data comes in at unpredictable intervals (potentially 100,000 of data points). It could contain anolog inputs (0-1023) or digital inputs (0-1), as well as other data. So basically, I have lots of specific timeseries, and I was wondering hwo I should go about jumping back in time and getting the whole system state.
03:40blur3dI’m fine with creating snapshots of data every second or something if that is required, and then that could be used to slide back in time to a past state
03:40blur3doh, and I am hoping to do this is clojurescript
03:41ddellacostablur3d: I guess my first instinct would be to snapshot everything with the timestamp as the hashmap key, perhaps?
03:41ddellacostablur3d: in an atom
03:42ddellacostablur3d: depending on how the data looks you could diff the previous state and store that each time, or start with some default state and just store diffs, computing the state at any given point?
03:43blur3dYeah, I’m just not sure how to keep as much resolution as possible in the data, and the history
03:43blur3dbecause a value could update 100s of times a second
03:44blur3dbut more likely 100Hz would be plenty
03:44ddellacostablur3d: ah, I see. Are the updates subsets of data, or do you get an entire snapshot?
03:45ddellacostablur3d: one idea is to use a counter and ignore updates unless you've hit a timeout/passed a threshold
03:45blur3dwell, the arduino input would have no real relation to past data for 50% of the time
03:45ddellacostablur3d: I see, so it's a snapshot of the entire system state? Sorry if I'm not getting it, never used an arduino
03:46blur3dwell, the state that matters…. not all the microcontroller inputs/outputs might be being used
03:47blur3dand they could just default to some initial state
03:47blur3dhttp://icant.co.uk/talks/h5/pictures/smashingconf/shorterjourney.jpg
03:47ddellacostablur3d: not sure what you mean by that image
03:48blur3dthat is kind of the same problem I am trying to solve.. I’m just really new to it and haven’t found many OSS to peer at
03:48blur3dsee how the player state is snapshot over time… ie. you can see where he was and where he is going
03:48Frozenlockblur3d: could you describe what you want to accomplish by keeping all these samplings?
03:48blur3din that case it is just x and y over time
03:49blur3dBasically, lets say I have a temperature sensor I hook up to the arduino
03:49ddellacostablur3d: well, the choice is simple it seems to me--you either keep an entire snapshot of state at a regular interval, or just updates to an initial state, which you compute on the fly if you need to go back in time
03:49blur3dit will give me back a temperature each microcontroller cycle (not at a set interval)
03:50blur3dI want to read those values into a clojurescript app in real time and display visualisations on the current state
03:50blur3d(obviously temperature is not important enough to read at 100Hz, but think of motors and such)
03:51FrozenlockEven with motors, I don't really see why 100hz... I mean, the human eye can't see that :-p
03:51ddellacostablur3d: I mean, there are a ton of variables in here that you will need to fine-tune, but the heuristic seems pretty simple
03:51blur3dno, but it would change the speed and therefore effect distance travelled etc
03:52ddellacostablur3d: obviously if you need to get something that is going to fool the eye, as Frozenlock says, it has to be fast enough--but doesn't need to be past 16 frames a second or something
03:52ddellacostawhatever that is. 24? I forget
03:52Frozenlock60 for a good FPS :-p
03:52Frozenlock(first person shooter)
03:53ddellacostablur3d: right; but that's why you take a snapshot at a regular interval regardless, and you make sure you can either compute the entire system's state, or it is all stored for that snapshot
03:53blur3dsure, I might use moving averages for the visualisations
03:53blur3dbut I was keen to somehow also keep mass data for playback/simulation later
03:53blur3dyeah, ok.. I’ll give it a go
03:53blur3dddellacosta Frozenlock thanks
03:53Frozenlockblur3d: I'd store a snapshot of all the values every MCU cycle
03:54ddellacostablur3d: I mean, I guess there is a tricky bit where you get something inside the threshold, if you are listening vs. polling
03:56Frozenlock(assuming you don't run it for an hour)
03:56blur3dyeah, I would just have to accept it may be lossy
03:56ddellacostablur3d: yeah, but (say if it was an animation output) as long as you fooled the human eye it doesn't matter if the update came in at T150ms and you played it back at T155ms or whatever
03:56ddellacostablur3d: anyways, good luck, hope this helped at least to think through it
03:56blur3dyeah, I have a better idea now… Thanks again
03:56FrozenlockI remember programming MCUs in C... without a repl...
03:56FrozenlockTerrible, terrible times.
03:58ddellacostahaha
03:58blur3dThe Arduino IDE doesn’t have a repl yet, haha
03:59ddellacostayeah, I vaguely remember doing a bit of that sort of thing, writing stuff into a terrible proprietary editor and then pushing it to the microcontroller
03:59ddellacostaI guess Arduino is better than that
04:02blur3dThis is the general idea of what I am working on http://vimeo.com/97903574 (15 min video). Basically a real-time dashboard for what exactly the arduino is doing
04:04Frozenlock"You sit at your desk and look at this tiny rectangle" Pfff, my rectangle isn't tiny
04:16blur3dhaha, he may of.. but he’s been doing similar stuff for a few years now
04:18blur3dI’ll take a look… it sounds nice
04:18blur3dand it seems fairly popular - I’ve never head of it
04:18FrozenlockIf you do use crossfilter, you should really take a snapshot of all the values everytime.
04:20blur3dok, well any value updates come in one at a time. I’ll work on getting the foundation setup, and then I’ll look at how much data I actually need/want
04:21blur3dthe difficulty is that I was hoping to let the users send data whenever they feel necessary… and that could be very often
04:21blur3dbut it may also be once a minute, or 10 minutes
05:22blahWhy does my page display only Test2 in the following code ? http://bpaste.net/show/C6qQOHrUAwdHWgQbKS0J/
05:22blahThis is attempting to use om
05:38SlotkenovWhat might I be doing wrong when in the repl "(cemerick.austin.repls/browser-connected-repl-js)" works fine, but "(require [cemerick.austin.repls :refer [browser-connected-repl-js]])" returns the error "CompilerException java.lang.ClassNotFoundException: cemerick.austin.repls, compiling:(/tmp/form-init4786187161975553725.clj:1:1)"?
05:48SlotkenovI forgot to quote in the require statement :)
05:54jonathanjhow do i concisely write: if (f.foo() && f.bar()) { X } else { Y } in clojure?
06:02Slotkenov@jonathanj (if (and (foo) (bar)) X Y)
06:21jonathanjhow do i give a typehint of an array of something? eg. Foo[]
06:27TEttingerjonathanj, ah that's a classic thing
06:27TEttingerthere's a good post on it...
06:27TEttingerhttp://www.learningclojure.com/2010/09/macros-and-type-hints-metadata-and.html
06:28clgvjonathanj: for objects there is "^objects"
06:28TEttingererr, http://asymmetrical-view.com/2009/07/02/clojure-primitive-arrays.html
06:31clgv,(-> (into-array Long/TYPE (range 3)) class ((juxt identity #(.getCanonicalName %))))
06:31clojurebot[[J "long[]"]
06:32clgv,(-> (into-array Long/TYPE (range 3)) class ((juxt #(.getName %) #(.getCanonicalName %))))
06:32clojurebot["[J" "long[]"]
06:35jonathanjthanks
06:58jonathanjhrm, so if i do: lein uberjar, i can't run the resulting jar as-is: Exception in thread "main" java.lang.NoClassDefFoundError: clojure/lang/IFn
06:58jonathanjpresumably i need some clojure stuff in my classpath but i'm not sure what or how
07:03jonathanjoh there is a separate standalone jar, my bad
07:21ambrosebsis it possible to extend an Object[] to a protocol?
07:22ambrosebsVerifyError (class: clojure/core/typed/array$eval13206, method: invoke signature: ()Ljava/lang/Object;) Incompatible object argument for function call java.lang.Class.getDeclaredConstructors0 (Class.java:-2)
07:22ambrosebsI seem to get that.
07:22ambrosebsInteger[] seems to work.
07:25clgvambrosebs: extend-protocol together with (java.lang.Class/forName "[Ljava.lang.Object;") worked
07:25ambrosebsah, I tried extend-type with (class (object-array []))
07:26ambrosebsweird that (class (make-array Integer 0)) worked for Integer[]
07:27ambrosebsright, Class/forName still gives me the same error.
07:27clgvambrosebs: again some core.typed "overload" like "fn" last time?
07:28ambrosebsclgv: most likely, I'll try somewhere else :P
07:29clgvI tried in an almost fresh repl ;)
07:29jonathanjhrm, is there a shorter way of writing (apply #(Foo. %1 %2 %3 %4) [12 34 56 78])
07:30jonathanj(in reality the args vector comes from splitting a string and is checked for exactly 4 arguments)
07:30vmarcinkohello, just wondering - if I increment some counter contained in plain clojure vector (integer element) a billion times, it will take significant amount of memory for this action since clojure's immutable structures don't upodate anything, but only add new data states in memory, (similar to Git)?
07:31ambrosebsclgv: https://gist.github.com/frenchy64/19e299d0c96524afc5d5
07:33clgvjonathanj: thats a record or deftype right? than there is (->Foo 12 34 56 78)
07:35jonathanjhmm?
07:36jonathanjit's a com.itext.text.Rectangle in this particular case
07:37jonathanji ended up using vec destructuring and :as
07:43clgvjonathanj: well than not ;)
07:44clgvjonathanj: in case of deftype and defrecord you get that convenience function
07:47ambrosebsI'm on java7 fwiw.
07:47ambrosebsI'll try clojure 1.6
07:47clgvambrosebs: Clojure 1.6 on Java 7 here
07:48ambrosebseh same error for me
07:48ambrosebsweird!
07:48razum2umvmarcinko: see transient topic
07:48razum2umvmarcinko: http://clojure.org/transients
07:49clgvambrosebs: https://www.refheap.com/87610
07:50clgvvmarcinko: transient vector and assoc! should do the trick
07:51razum2umfolks, is there any clojure online playgrounds like http://www.tryerlang.org/ ?
07:52nathan7razum2um: http://tryclj.com/
07:52clgvrazum2um: http://tryclj.com/
07:52clgv:P
07:55razum2umoh, not correct example, i asked for http://www.jsfiddle.net/ more. you gave link to refheap, but what if i just want to fork&edit code on link above with instant feedback from repl
08:00ambrosebsclgv: huh, does (blubb (object-array 1)) work for you?
08:00ambrosebsinto-array works for me
08:00razum2umhm, realized that I thought about lighttable online + collaborative editing like gits
08:01razum2ums/gits/gist/
08:01clgvambrosebs: no it does not
08:01ambrosebsI have no idea why
08:03ambrosebs,(identical? (class (object-array 0)) (class (into-array Object [1 2])))
08:03clojurebottrue
08:03petrusthow do I include an unstable clojure dependency that is not on clojars? e.g. reagent 0.4.3 ?
08:04vmarcinko<razum2um>: thanx
08:04vmarcinkorazum2um: thanx
08:05hyPiRionpetrust: git clone the repo, then perform `lein install` in its root directory
08:07clgvambrosebs: thats pretty damn weird
08:07razum2umyep, such already exists but doesnt support clj - https://eval.in/
08:10clgvambrosebs: ##(let [a1 (object-array [1 2]), a2 (into-array Object [1 2])] (println (identical? (class a1) (class a2)) (java.util.Arrays/equals a1 a2)))
08:10lazybot⇒ true true nil
08:11michaelr525hello
08:14ambrosebsclgv: looks like into-array is created with reflection and object-array is created with java syntax.
08:14ambrosebsthe only difference I can see.
08:15clgvambrosebs: should be the same though? "length" is in fact done via java.reflect.Array as well afaik
08:16clgvinteresting mail topic for clojure-dev though ;)
08:16ambrosebsperhaps there's a subtle difference between Array.newInstance(Object, 1) and Object[1]
08:16clojurebotIt's greek to me.
08:17clgvambrosebs: wouldnt that even violate the java spec?
10:22Klaufiri need some help understanding dependency management in cider + lein
10:23Klaufirfirst, how do I download dependencies?
10:24Klaufirsay I want 'data.json', and have the following line in project.clj
10:24Klaufir:dependencies [[org.clojure/clojure "1.6.0"] [org.clojure/data.json "0.2.5"]]
10:24cbpyou declare them in your project.clj and lein will download them automatically if it needs to
10:24cbpafter you do something like lein repl
10:24KlaufirI see
10:25teslanickYou can force it by running `lein deps` on the command line
10:25Klaufirthanks
10:25Klaufirand how do I make sure these deps are available in the REPL after cider-jack-in ?
10:25Klaufirfor example when editing core.clj, and have a project file with [org.clojure/data.json "0.2.5"] included
10:26KlaufirI can't seem to access the json functions
10:26Klaufiris cider-jack-in supposed to resolve dependencies using lein ?
10:28cbpcider-jack-in calls lein repl so yes
10:29Klaufircan you point me towards some useful documentation regarding dependency management in clojue ?
10:29Klaufirso far, its very unintuitive, confusing and buried behind lein magic
10:30cbphttps://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md
10:30_Atom_HELLO IS MY FRIEND HENRY HERE?
10:30_Atom_LOL
10:31Klaufircbp: exactly what I was looking for, thank you :)
10:31deathknightwhat's this doing here
10:31_Atom_fgt shit
10:31rplacaKlaufir: I think you might be confusing the dependency management with accessing namespaces
10:32rplacaKlaufir: if your project.clj is set up like you say, you should have the dependency available and you just need to do a require when you want to access it
10:33rplacae.g. at the repl: (require '[data.json :as json])
10:34rplacaor in the ns form of your core.clj: (:require [data.json :as json])
10:37Klaufirrplaca: thanks :)
10:38rplacaKlaufir: hope that helps!
11:43orendhey, I have a midje question: is there a way to ask midje to load the test lein profile? I want to make sure it uses the test database, and I want to clear it before the tests
11:44orendcore.test is loading the test profile in lein, midje doesn't seem to do it
11:52gfredericksorend: `lein with-profile +test whatever-the-midje-task-is` will do it
11:52gfredericksand you can make an alias for that
12:17dgleesondoes memoize have any memory impacts I should be considering before using it?
12:17arrdemdgleeson: memoize has an unbounded cache size..
12:18ambrosebshttps://github.com/clojure/core.cache
12:18arrdemat least clojure.core/memoize does... core cache fixes that nicely.
12:18Bronsathere's also core.memoize that's built on top of core.cache and it's friendlier
12:19dgleesoninteresting thanks!
13:02mmitchellanyone here use clj-logging-config for log configuration?
13:21bbloomBronsa: symbol-macrolet was super easy to add & solves my problem quite nicely :-)
13:22AeroNotixJust been to EuroClojure. What's with the bruce meme?
13:24seangroveAeroNotix: What bruce meme?
13:26AeroNotixseangrove: a lot of talks contained a picture of a guy called "Bruce" with a goatee
13:30AeroNotixhttps://skillsmatter.com/members/otfrom
13:30AeroNotixoh this guy
13:31arrdemI'd bet he's an organizer and it was presenters screwing with him
14:10amalloybbloom: what problem did symbol-macrolet solve? i'm always excited to hear about new uses of it
14:11bbloomamalloy: in eclj i didn't want to special case fields inside deftype method bodies. so i used symbol-macrolet to expand field names to (.-field this) style forms
14:12amalloyah. sounds perfect, yep yep
14:12Bronsabbloom: oh so it worked, cool
14:12bbloomBronsa: yup: https://github.com/brandonbloom/eclj/commit/bb885d02079387c675065d3347754f4bb1e54e29
14:12bbloomand https://github.com/brandonbloom/eclj/commit/d99ba8f2fe72b71d360e602f2c466faf03ec01ac
14:12bbloom(deftype is still a slow as shit dirty hack, but i'm not worried about the perf of it until i get to the compiler)
14:13bbloomgoing to generalize set! too... basically to CL's setf
14:13Bronsawoah
14:14Bronsabbloom: that sounds fun but I'm not really sure if it would be really useful in clj given absence of pervasive mutability
14:14Bronsabbloom: do you have specific use-cases for that or is it just something cool you want to implement?
14:17bbloomBronsa: i need to rework my code for set! anyway to understand symbol macros & it's pretty easy to just make that a protocol... effectively providing setf
14:17bbloomright now it's an if/else and will become a cond, so might as well make it a proto fn and call it done :-P
14:18bbloombut i don't need field setting yet, so i'll cross that bridge when i come to it
14:19bbloomi'm doing JIT development :-)
14:21Bronsabbloom: ah yeah, I probably need to do something like that too
14:22Bronsaright now (set! foo bar) compiles to a setfield while (set! (.-foo this) bar) uses reflection IIRC
14:22Bronsait should definitely be possible to make the latter compile to a setfield too
14:23Bronsanevermind it already does.
14:23Willis1bbloom
15:28caternagh
15:28caternIs there a "Java for Clojure developers" tutorial anywhere?
15:28ndalyhaha
15:28ndalyI thought the same thing
15:28caternI've never actually worked in Java before, so
15:31mikerodIs it safe to use (clojure.lang/RT/nextID) as a way of getting a unique identifier within a given JVM instance?
15:31cbpI recommend Java in Action which is probably as close as you can get
15:31mikerodI know this is used by `gensym`
15:31mikerodbut here, we don't actually need a symbol and do not want the overhead of creating one
15:32caterncbp: I really don't want to learn Java, though
15:32catern(as the exposure I have had to it, even before Clojure, convinces me it is garbage)
15:32ndalyit is
15:33caternI come to Clojure from Lisp, not Java :)
15:33cbpI'm not sure how to help you learning something without learning it
15:34ndalyRich Hickey's talks (on youtube) entitled Clojure for Java Programmers is a gentle way to get some indirect understanding of the Java you might want to know
15:34ndalywhile learning some interesting stuff about Clojure and it's implementation
15:34mikerodRich Hickey also has a talk Clojure for Lisp programmers
15:34ndalythat one won't play past like minute 6 for me
15:34ndalywhich is killing me, cuz I really want to watch it
15:35mikerodhttps://www.youtube.com/watch?v=cPNkH-7PRTk
15:35mikerodI've listened to both the Java and Lisp variety. The Lisp one is probably more insightful in my opinion. However, I'd think they both have value.
15:35mikerodNot to mention the Lisp one does assume you know something about Lisp. However, this is what catern said he was from.
15:36ndalyyeah, that video dies at 6:35
15:36mikerodweird
15:37mikerodI haven't tried
15:37mikerodit used to work :P
15:39dbaschmikerod: I would use my own atom rather than rely on nextID
15:39cbpwhy not a uuid4 or something?
15:40dbaschcbp: he said he doesn't need uuids, only something unique within that jvm
15:41Shayanjmcatern: why dive into java when you know clojure?
15:41ShayanjmI would imagine you can accomplish the same thing(s), just without consistently shooting yourself in the foot
15:41caternShayanjm: I don't want to dive into Java
15:41dbaschShayanjm: because using Clojure properly requires knowing Java
15:41dbaschto some extent, at least
15:41ShayanjmThat's fair, but Java development is INCREDIBLY OO centric
15:42Shayanjmkeeping code DRY is an impossible feat
15:42caternShayanjm: I want to lightly touch the surface of Java, while heavily insulated by Clojure's protective embrace
15:42dbaschShayanjm: so? You don't need to code in java
15:42Shayanjmdbasch: I know - that's why I was asking why catern was asking about 'java for clojure devs'
15:42caternShayanjm: also I only need to be able to read Java code, not write it. And occasionally run it
15:42Shayanjmif he wanted to actually -learn- java
15:43mikerodcbp: As dbasch said, I do not want to pay any overhead for getting a UUID
15:43Shayanjmor learn how to build stuff with clojure while using java interfaces
15:43Shayanjmgotcha catern
15:43mikerodI only care about the uniqueness at the per-JVM instance level
15:43mikeroddbasch: Why make your own atom?
15:43mikeroddbasch: The RT/nextID method is not something you think is stable?
15:44dbaschmikerod: it's not a documented feature of the language
15:44dbaschmikerod: and it will leave holes in your ids, fwiw
15:45dbaschall it does is use a java AtomicInteger I believe
15:45jconnoll1quick and dumb question... I have a vector [1 2 3 4 5], I want to create another vector that's just [0.0 0.0 0.0 0.0 0.0] of length of the first vector...
15:46mikeroddbasch: holes do not matter for me, but it being undocumented makes some sense
15:46cbpjconnolli: (vec (repeat (count my-vec) 0.0))
15:46jconnollycbp: beauty, thanks
15:47ndalygod I love how concise that is
15:48caternI wish there was a #(+ % 5) style form for defining functions returning simple data structures, like say #[%] or #{:value %}
15:49dbaschyou could also do (vec (for [x my-vec] 0.0))
15:49caternSimple transformations I mean
15:50ndalycatern: I'm confused about what you want to be able to do
15:50caternndaly: define a function returning a vector or map, parameterized with %
15:51catern(and the variations on %)
15:51dbaschalso, (mapv (constantly 0.0) my-vec)
15:51caternconstantly
15:51caternThat is a nice function
15:52caternthanks dbasch, did not know of it
15:52dbasch,(mapv (constantly 0.0) [:a :b :c])
15:52clojurebot[0.0 0.0 0.0]
16:13fifosineIs there a standard/good-practice for defining and loading properties from a properties file? For example, I'd like to write a properties file for database credentials and keep it separate from version control.
16:14bbloomfifosine: something wrong with slurp and pr-str ?
16:14bbloomer read-str ?
16:15Raynesread-str is a thing?
16:15bbloomargh.
16:15bbloomread-string
16:15bbloom(def read-str read-string)
16:15ttasteriscouse environ
16:15ttasterisco,(google "clojure environ")
16:15clojurebot#<CompilerException java.lang.RuntimeException: Unable to resolve symbol: google in this context, compiling:(NO_SOURCE_PATH:0:0)>
16:15bbloomthen somebody do a vary-meta to :deprecate read-string :-P
16:16RaynesWell, he almost certainly wouldn't want read-string.
16:16fifosinebbloom: I'm sure there are many ways to do this. Using java.util.Properties is recommended here https://stackoverflow.com/questions/7777882/loading-configuration-file-in-clojure-as-data-structure. I am curious if there is an idomatic way to do this.
16:16ttasteriscohttps://github.com/weavejester/environ
16:16Raynes$google clojure environ
16:16lazybot[weavejester/environ · GitHub] https://github.com/weavejester/environ
16:16bbloomfifosine: depends on what context you want idioms from
16:16fifosineA clojure context.
16:16bbloomif you're deploying a unix process on heroku or in docker or whatever, use environment
16:17bbloomif you have a jvm cluster w/ devops that know those tools, use java properties
16:17RaynesI generally use environment variables for most of my configuration. If I want configuration files, I serialize Clojure data structures by printing them to files and reading them with clojure.edn/read-string
16:17RaynesOr I use toml.
16:17RaynesLately I mostly use toml for configuration I expect a user to have to modify.
16:17bbloomif your config is too big for the environment, put a file path in the environment
16:18fifosinebbloom: My config won't be big, it's just going to be a db user and pass as of now
16:18bbloomif you don't know anything about java properties, then ignore them
16:18bbloomjust use the env
16:18RaynesYeah, you don't want properties for this.
16:18fifosinebbloom: When you say, "use the env" do you mean use environ?
16:18RaynesENVIRONMENT VARIABLES
16:19RaynesEnviron can handle those for ye
16:19bbloom,(get System/getenv "PATH")
16:19clojurebot#<CompilerException java.lang.RuntimeException: Unable to find static field: getenv in class java.lang.System, compiling:(NO_SOURCE_PATH:0:0)>
16:19RaynesThough I personally never totally got the purpose of environ.
16:19bbloom,(get (System/getenv) "PATH")
16:19clojurebot#<AccessControlException java.security.AccessControlException: access denied (java.lang.RuntimePermission getenv.*)>
16:19bbloomaw
16:19RaynesI generally just do what bbloom is desperately struggling to do.
16:19bbloomi swear that works locally
16:20RaynesHaha, yeah, the second one is fine.
16:20fifosinelul
16:20RaynesI think (System/getenv "PATH") would also work.
16:20RaynesBut I can't recall for certain.
16:20bbloomRaynes: yup does
16:24bbloomi'm still trying to understand the equals/equiv and hashCode/hasheq dichotomy
16:24bbloomwhy doesn't hashCode delegate to hasheq ?
16:25ttasterisco,(doc hasheq)
16:25clojurebotTitim gan éirí ort.
16:28bbloomhttps://docs.google.com/a/thinkrelevance.com/document/d/1DT2uXlAwH5NstgYSeqbOXb_8K6Gwnw99QksCaUKpCjU/edit?pli=1 says:
16:28bbloomThe Java Collections API specifies required algorithms for calculating the hash code of sets, maps, lists, etc from their elements. We wish to be compatible with the collections API
16:28bbloomblargh :-P
16:29tolitiusis there a way to see what is (file name/function) being compiled? I have a dozen of files, one of which needs aot [hence compiles all the dependent ns], and it takes about 5 minutes to finish (where it should take about 5 seconds), I just want to figure out which file causes the compilation hiccup.
16:30andyf_bbloom: Does that answer your question about why they both exist, or only adds to it?
16:30bbloomandyf_: it gives me a guess, but i'm still not totally sure
16:31bbloomandyf_: my guess is that java.collections tests hashcode equality in some cases & needs to work with heterogeneous collection impls
16:31bbloommaybe?
16:32xeqibbloom: didn't the 1.6 hash changes break that compatibility?
16:32bbloomxeqi: best i can tell both code paths are still there
16:33andyf_I am not 100% in the loop on Clojure design decisions, I do believe that they wanted equals and hashCode to be consistent for Clojure collections and their nearest equivalent in the Jaca Collections library
16:33xeqiah, found http://dev.clojure.org/jira/browse/CLJ-1372
16:33xeqiwhich is about the extent of my knowledge in this area, other then stuff is happening/happened
16:34andyf_xeqi: 1.6 should not have changed hashCode ret val for anything
16:34andyf_It did change hasheq ret val for many things
16:40dbaschfifosine: you mean a .properties file in the typical java format?
16:43dbaschnever mind, had missed the rest of the backlog
16:58fifosineHow do I debug this issue? http://pastebin.com/3HQFwRmw I know that this jar exists in the repo.
17:01xeqififosine: by carefulling checking the group:artifact:version in the error
17:01xeqi(missing a q I believe)
17:04fifosinexeqi: Still getting it :/ http://pastebin.com/1y6AuLVT
17:16xeqififosine: that version doesn't exist by that group/artifact: http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22postgresql%22%20AND%20a%3A%22postgresql%22
17:16xeqiperhaps you want group "org.postgres"
17:16xeqibah
17:16xeqiorg.postgresql
17:16bbloomis there some way to stop ctrl-c from closing `lein repl` ?
17:16bbloomi want to actually be able to interrupt an evaluation...
17:16fifosinexeqi: Looks like that was it!
17:16amalloybbloom: i don't think there's a portable way, but https://github.com/flatland/useful/blob/develop/src/flatland/useful/java.clj#L10-L16 works on some jvms. register a handler for sigint, maybe?
17:16bbloomamalloy: but the damn nrepl middleware is called "InterruptableEval"
17:16bbloomc'mon now cemerick/technomancy
17:16bbloomet al
17:16andyf_bbloom: In my quick test on Mac OS X with Lein 2.3.4, it already does what you want. Lein 2.4 the behavior changed
17:16cbpmy lein repl only quits by ctrl-d
17:16bbloomandyf_: i just upgraded recently, which would explain why i only started noticing this... i could have sworn it used to work
17:16cbpUnless i spam control-c it too many times apparently
17:16amalloyoh, yeah. in lein repl, C-c just interrupts for me
17:16cbps/it//
17:16andyf_Lein upgrade 2.3.4 should work to downgrade
17:16bbloomandyf_: but i want the latest lein for https://github.com/greglook/whidbey
17:16andyf_I usually keep a numbered backup of Lein bash scripts before upgrading
17:16andyf_I would have guessed you were kidding when you gave that URL, but looks like a real thing :-)
17:16bbloomi wrote fipp in the hope that somebody would integrate it in to nrepl/lein. whedbey realizes that dream :-)
17:16bbloomwhidbey*
17:16andyf_File a Lein bug, and see where it goes - or maybe there is one already?
17:16dbaschlein 2.4.2 on OSX, ctrl-c doesn't kill it
17:16andyf_It does for me
17:16bbloomhttps://github.com/technomancy/leiningen/issues/1583
17:16andyf_Not sure, but may be a dupe of 1570
17:17andyf_Holy cow - 1538 issues closed on leiningen. That's a bunch
17:19xeqiandyf_: and all as a labor of love / no corporate donations
17:19xeqiperhaps sponser would be a better term there
17:19cbpyou can dotane to tehcnomancys git tip :-P
17:19cbpdonate even
17:20arrdemI think he gets like $3.50/wk...
17:20arrdemwhich is pretty absurd given how much value lein generates.
17:20andyf_I've never donated via git tip before. URL handy?
17:20arrdemhttps://www.gittip.com/technomancy/
17:21cbpclearly he shouldve been involved in npm instead
17:21arrdemlol
17:22andyf_No way to do 1 time gift, only periodically?
17:27bbloomweird... i'm trying to use yourkit on something in the repl & java.io.PushbackInputStream.read is running on an agent thread (i'm not using agents) & shows as the primary hot method
17:28bbloomit's "own time" metric is climbing rapidly
17:28bblooms/it's/its
17:28amalloybbloom: it's consuming 100% of a single thread
17:28amalloythat happens all the time with repl/swank. i just right-click and Ignore that method
17:28bbloomamalloy: yeah, but why is it doing anything, i'm not evaluating anything
17:29bbloomwhat's it think it's doing?
17:29amalloyit's waiting for you to type something
17:29amalloythat's blocking, so it isn't taking up actual cpu time, but it is time a thread is spending inside a method
17:30bbloomodd. hadn't seen that before
17:30amalloyi think that's the general outline, anyway
17:30amalloyhappens to me anytime i use yourkit on a jvm i'm also attached to via swank
17:30bbloomgood to know. i had never noticed it with visualvm
17:42bbloomi apparently have no idea how to use yourkit
17:42bbloom(time ...) reports 11 seconds. sum of "own time" yourkit is ~2 seconds
17:42bbloomthose don't add up....
17:43amalloyown time doesn't include any other functions called by f, in (time (f))
17:43bbloomamalloy: i said "sum of"
17:44amalloyoh. how are you even summing the own time of all methods invoked by a specific instance of (time (f))?
17:44bbloomi manually summed the top 10 calls or so, then multiplied the value of the 11th by the approximate number of rows
17:44bbloomremaining rows
17:44bbloomso that should be an approximate upper bound
17:44bbloombut it's 2ish seconds, instead of 11
17:45bbloomeven if that's cpu time, i doubt there's 9 seconds of wall clock waiting
17:49DilatedPupils|THpen tested a site today, able to intercept the request going to paypal and changed the payment to 1p, how many of the sites use the wrong implementation
17:49arrdemDilatedPupils|TH: cool result, wrong channel?
17:50DilatedPupils|THsure, sorry
17:50bbloomamalloy: found the perf problem with some manually placed (time ...) statements. easy fix
17:50bbloommy experience with profilers is almost always pretty poor
17:54andyfdbasch: Try an infinite loop like (count (range)) and then ctrl-c to interrupt it
17:55dbaschandyf: works just fine
17:56andyfMust be some other diff in our software I guess
18:04dbaschandyf: Leiningen 2.4.2 on Java 1.7.0_51 Java HotSpot(TM) 64-Bit Server VM
18:08andyfSame here, plus os x 10.8.5 and no ~/.lein/profiles.clj file. Throws exception and exits Lein repl consistently when I try to interrupt evaluation. Seems like Lein/reply folks are on the issue.
18:12amalloybbloom: you must be looking at the wrong stuff. i find yourkit often points me right at the hotspots
18:13bbloomi guess i just have no idea how to use it, b/c i put the hotspot back in and tried jvisualvm & it pointed it out right away
18:13amalloyi turn on cpu sampling, let it run for a while, capture a snapshot, and then look around in the method list and/or hotspot list
18:14bbloomthat's exactly what i did
18:14amalloymaybe computers just find you offensive
18:14bbloomlike true
18:15hiredmanmaybe you should have written a map reduce job in erlang
18:15bbloomhuh?
18:16hiredmanbad advice for every situation
18:16ttasteriscolol
18:19Shayanjm_https://gist.github.com/shayanjm/7a085ad77514290c4986 <-- this code immediately prints "Elapsed time: 0.899 msecs"
18:19Shayanjm_but it actually returns values much later
18:19Shayanjm_any ideas how I can capture the WHOLE time it takes to return everything to the last form?
18:20bbloomput a doall on your pmap
18:20hiredmanugh
18:20hiredmanpmap inside a transaction
18:20bbloombut yeah, what hiredman said. don't do that
18:20hiredmanbbloom: that may actually deadlock
18:20bbloomthat code is all kinds of wrong
18:21hiredmandoes pmap use agents? maybe I am thinking of seque
18:21bbloomhiredman: it's built from futures
18:21hiredmanalso ref-set
18:21bbloomor maybe it's delays
18:22amalloyhiredman: pmap uses futures, seque uses agents
18:22Shayanjm_should i throw the pmap into a let, and then throw that into the refset?
18:22hiredmanterrible thing #1 using pmap, this is indefensible, #2 using the stm, if you try very hard you may be able to defend this
18:22amalloybbloom: http://i.imgur.com/ENtJs.png is the reference from hiredman you seem to have missed
18:23Shayanjmhiredman: very very very new to clojure
18:23Shayanjmwhat should I do instead?
18:23bbloomamalloy: lol awesome
18:23hiredmanShayanjm: depends what you are doing
18:24Shayanjmhiredman: I have a list of URLS. I have a function that 'gets' the article content body from the URL and stubs it into a string
18:24hiredmanShayanjm: but, basically, write functions that take immutable values as arguments, and return an immutable value as a result
18:25Shayanjmand then I have another function that analyzes the sentiment of the string glob, and returns a list of numbers signifying each sentence's sentiment
18:25ShayanjmI would like to be able to iterate through the list of URLS in my 'newswire' ref, and analyze each article's sentiment and store the result in a second ref
18:25hiredmanwhy is newswire a ref?
18:26hiredmanis it logically a collection of values, or a work queue little machines pull work from?
18:28Shayanjmhiredman: It was an atom, but I assumed that I would need some level of transactional guarantee on it and the second 'thing' (whether it's an atom or a ref)
18:28Shayanjmthat way I don't have a set of sentiment analysis results that are out of sync with the list of URLs
18:30dbaschShayanjm: I would make sentiment analysis results be a function of a url snapshot, which is immutable
18:30Shayanjma url snapshot?
18:30hiredmanShayanjm: that just isn't a good way to break it up, have a single function that takes a {:title … :url …} and returns a {:title … :url … :sentiment …}
18:30dbaschShayanjm: e.g. nytimes.com/index.html at 3:29 PST 6/28/2014
18:31Shayanjmhmmk
18:31hiredmanthen replace newswire with a queue of {:title … :url …}
18:31dbascha url doesn't have a sentiment, the content does
18:31hiredmanthen fire off futures or use an executor directly that runs the function taking one element from the queue at a time
18:32ShayanjmYeah I'm not sure about that fundamentally
18:32Shayanjmas it stands right now: each component is simplistic and straight forward
18:32hiredmancollecting the results somewhere (maybe another queue for whatever the next stage is)
18:32dbasch(waiting for an example like http://sad-domain/sad-path-to-sadness.html)
18:32ShayanjmI'm not sure what composing the functions into one large 'get-sentiment-from-url' function will do for the time issue I was running into
18:33hiredmanneither pmap nor the stm are simple
18:33Shayanjmstm?
18:33hiredmanShayanjm: software transactional memory, what dosync and refs are
18:33ShayanjmSure so arguably I don't even need the second ref
18:34Shayanjmit was just for the sake of having something available to capture the results of the functions
18:34hiredmanyou should not need *any* refs
18:34ShayanjmI think a single atom is necessary for managing the data coming in from the API, is it not?
18:34hiredmanShayanjm: atoms are not refs
18:34justin_smithShayanjm: http://clojure.org/refs this explains refs / stm
18:35hiredmanShayanjm: and in any case I suspect a work queue would be better
18:35ShayanjmProbably, hiredman. Do you suggest I build one myself or is there a library option available?
18:36hiredmanShayanjm: java.util.concurrent has a few queues
18:37ShayanjmAnyway, as I mentioned before - I don't know how this has anything to do with the weirdness surrounding the time function
18:37hiredmanyou could pull in core.async and use a channel as a work queue too
18:38hiredmanShayanjm: pmap is sort of lazy
18:38Shayanjmdoes anyone know why time is being printed before every form has finished evaluating?
18:38Shayanjmoh really?
18:38bbloomShayanjm: i answered your question in my very first comment: try doall
18:38hiredmanShayanjm: did you read the doc string for pmap?
18:38justin_smithShayanjm: a function can return a result that is lazy before the result is realized
18:38hiredman(doc pmap)
18:38clojurebot"([f coll] [f coll & colls]); Like map, except f is applied in parallel. Semi-lazy in that the parallel computation stays ahead of the consumption, but doesn't realize the entire result unless required. Only useful for computationally intensive functions where the time of f dominates the coordination overhead."
18:38bbloomit will prevent the laziness.... butthen you should listen to hiredman
18:38Shayanjmok thanks bbloom
18:38ShayanjmI see
18:39hiredmanbut pmap is terrible
18:39hiredman~pmap
18:39clojurebotpmap is not what you want
18:39bbloom(dec pmap)
18:39lazybot⇒ -1
18:39bbloomsheesh, that's too almost positive
18:39bbloom(dec pmap)
18:39lazybot⇒ -2
18:39bbloom(dec pmap)
18:39lazybot⇒ -3
18:39bbloom(dec pmap)
18:39lazybotDo I smell abuse? Wait a while before modifying that person's karma again.
18:39bbloombetter
18:40Shayanjmwait so what is pmap useful for then?
18:40hiredmannothing
18:40ShayanjmMy understanding is that it's just like map, but it threads each iteration?
18:40Shayanjm(apparently clojure for the brave lied to me)
18:41bbloomthat is what it is, it's just that that is not useful
18:41hiredmanit isn't just that
18:41tuft_is there a preferred alternative these days?
18:41justin_smithbbloom: wouldn't it still be useful, if your function was more expensive than the future spawning overhead?
18:41hiredmanit also imposes an ordering on the results, it trys to run only as many jobs as there are cores at a time
18:41hiredmanit is semi lazy
18:41hiredmanbut then does weird things on chunked seqs
18:42hiredmanall of those things are basically things you never want
18:44hiredmanI recommend getting familiar with the executors framework http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Executors.html http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ExecutorService.html etc
18:45hiredmana fundamental problem of pmap is it takes in a seq and produces a seq
18:45hiredmanthe seq abstraction is terrible for parallelism because it enforces linear access
18:46tuft".. but i was promised if i used seqs and maps i'd get parallelism for free? 😢 "
18:47hiredmanby who?
18:48tufthaha
18:48tuftcan't remember exactly where that came from
18:48hiredmanhttp://xahlee.info/comp/i/ICFPAugust2009Steele.pdf
18:48tuftgenerally getting more abstract than a for loop seems to have that promise though
18:49hiredmansure
18:49hiredmanin order to have parallelism you need a datastructure with random access
18:50tuftthat makes sense
18:51dbaschhiredman: that's not strictly true, you can have a sequential pipeline of things that execute in parallel
18:55hiredmandbasch: concurrent vs. parallel
18:56dbaschhiredman: yes, I meant parallel, as in a factory pipeline with workers doing things in parallel
18:57danielszmulewiczIs clj-time still the best option to work with times in Clojure? I need to determine if a given date is in the future.
18:57dbaschin order to have parallelism you just need entities who have work to do
18:57hiredmandbasch: they are not concurrent, the "pipeline" sychronizes access
18:58dbaschhiredman: you said parallelism, not concurrency
18:58seancorfielddanielszmulewicz: depends on what format your initial date is... java.util.Date or Joda Time?
18:58danielszmulewiczseancorfield: java.util.Date (it's coming from Monger)
18:58seancorfieldAt World Singles we use both date-clj (for java.util.Date stuff) and clj-time for more complex stuff
18:58seancorfielddate-clj/before? is probably the easiest then
18:59justin_smith,(compare (java.util.Date.) (java.util.Date.)) danielszmulewicz
18:59danielszmulewiczseancorfield: Very cool. Thank you.
18:59clojurebot0
18:59hiredmandbasch: I said lots of things
18:59justin_smithyou don't need to get fancy for that
18:59danielszmulewiczjustin_smith: Thanks. That's cool as well.
18:59justin_smithI mean if you need to do math on time objects, or read format strings, yeah use a lib
18:59dbaschhiredman: I was commenting on "hiredman: in order to have parallelism you need a datastructure with random access"
19:00justin_smithbut you don't need anything but the built in class for comparing sequentiality
19:00danielszmulewiczjustin_smith: Just this one, and maybe one or two more.
19:00amalloy&(frequencies (repeatedly 10000 #(compare (java.util.Date.) (java.util.Date.))))
19:00lazybot⇒ {0 9991, -1 9}
19:00justin_smithfascinating
19:01amalloynot really important to this discussion, but i thought you might like it, justin_smith
19:01justin_smithindeed
19:01danielszmulewiczamalloy: Care to explain to a dummy?
19:01amalloydanielszmulewicz: you build two date objects and compare them. usually, they're in the same millisecond
19:01ndalywow
19:01amalloybut every so often, you slip across a millisecond boundary between building the first and building the second, so they compare as different
19:01danielszmulewiczamalloy: Oh, nice.
19:02ndalywait, is that building 10000 pairs of date objects?
19:02amalloyyeah
19:02ndalyvery nice
19:02amalloyi suppose it would have been more apropos to generate them all in parallel with pmap
19:03justin_smithyeah, the jvm handles micro-liftime objects very nicely
19:03ndalyI wonder how much of the JVM being good can be attributed to it needing to make up for Java being bad
19:04justin_smithndaly: I think there is more the fact that very well funded companies poured a lot of resources and exceptional talent into the jvm
19:05amalloyincidentally, that frequency chart gives a good estimate of how long it takes to construct a Date object. 0.1% of a millisecond, right? so ##(time (dotimes [_ 1000] (java.util.Date.))) should take about 1ms
19:05lazybot⇒ "Elapsed time: 7.151076 msecs" nil
19:06amalloyhmph. i want a refund. i don't know why that's off by a factor of 7
19:06hiredmanthe jvm it does things
19:09danielszmulewicz(+ seancorfield)
19:09danielszmulewiczhehe, how does this karma things work again?
19:09oskarkvinc
19:09danielszmulewiczright, thanks
19:09danielszmulewicz(inc seancorfield)
19:09lazybot⇒ 13
19:09amalloyhiredman: yeah, i guess that's what it is. if i go from 1000 dates to 10000, the time taken only doubles
19:09danielszmulewicz(inc justin_smith)
19:09lazybot⇒ 51
19:09seancorfieldthank you danielszmulewicz!
19:10danielszmulewiczseancorfield: Thank you!
19:10danielszmulewicz(inc amalloy)
19:10lazybot⇒ 134
19:12dbasch&(time (dotimes [_ 1000]))
19:12lazybot⇒ "Elapsed time: 3.850407 msecs" nil
19:13dbasch(dec dotimes)
19:13lazybot⇒ -1
19:13dbasch,(time (dotimes [_ 1000]))
19:13clojurebot"Elapsed time: 0.164555 msecs"\n
19:14bbloom,(dotimes [_ 10] (time (dotimes [_ 100])))
19:14clojurebot"Elapsed time: 0.136017 msecs"\n"Elapsed time: 0.004059 msecs"\n"Elapsed time: 0.003686 msecs"\n"Elapsed time: 0.00368 msecs"\n"Elapsed time: 0.003563 msecs"\n"Elapsed time: 0.003803 msecs"\n"Elapsed time: 0.003647 msecs"\n"Elapsed time: 0.003657 msecs"\n"Elapsed time: 0.003569 msecs"\n"Elapsed time: 0.003598 msecs"\n
19:14bbloom,(dotimes [_ 10] (time (dotimes [_ 1000])))
19:14clojurebot"Elapsed time: 0.152137 msecs"\n"Elapsed time: 0.025343 msecs"\n"Elapsed time: 0.209708 msecs"\n"Elapsed time: 0.002701 msecs"\n"Elapsed time: 0.00244 msecs"\n"Elapsed time: 0.002395 msecs"\n"Elapsed time: 0.002409 msecs"\n"Elapsed time: 0.002404 msecs"\n"Elapsed time: 0.002389 msecs"\n"Elapsed time: 0.002377 msecs"\n
19:14bbloomcomputers. how do they work?
19:16gfredericks,(macroexpand-1 '(dotimes [_ 1000]))
19:16clojurebot(clojure.core/let [n__4379__auto__ (clojure.core/long 1000)] (clojure.core/loop [_ 0] (clojure.core/when (clojure.core/< _ n__4379__auto__) (recur (clojure.core/unchecked-inc _)))))
19:17danielszmulewicz$help
19:17lazybotYou're going to need to tell me what you want help with.
19:17amalloywhat in the world. did i turn this into #dotimes?
19:17danielszmulewiczdbasch: What is the meaning of the ampersand at the beginning of the expression you typed earlier?
19:18cj3kimhi, in (defn [& args] ;code ) is args an vector?
19:18dbaschdanielszmulewicz: asking lazybot to evaluate
19:18amalloycj3kim: it's a seq
19:18danielszmulewiczdbasch: is that not the coma?
19:18dbaschdanielszmulewicz: that's clojurebot
19:18cj3kimamalloy: thank you!
19:18danielszmulewiczdbasch: oh, how many bots do we have here?
19:19amalloyat least two. jury's still out on justin_smith
19:19dbaschdanielszmulewicz: I am not a bot
19:19danielszmulewiczhehe
19:19dbaschI am a 13 year old boy from Ukraine
19:20ttasteriscoew
19:21bbloomBronsa: i think i'm gonna have to start on the compiler sooner rather than later... the more of core i make symbolic, the slower everything goes... i'm working on lazy seqs now, it's making everything 20X slower (which i guess is expected for interpreter vs compiler)
19:23amalloybbloom: i wonder, are you chunking lazy seqs? that brings a surprisingly large speedup
19:24bbloomamalloy: just the overhead of the itnerpreter for first/next/seq dispatch is killing me
19:27justin_smithamalloy: me? Ha! I would appreciate it if you would continue.
19:28amalloyWhy would you appreciate it if I would continue?
19:29justin_smithWhat do you think?
19:29dbaschnow this is #clojure-chatbots
19:33TEttingerbbloom, is this for clojure-in-clojure?
19:33bbloomTEttinger: not for the official c-in-c stuff going on in tools analyzer etc. it's for my hacky thing
19:33amalloydbasch: for some reason back in march i spent a few days as /nick amalloybot instead of amalloy. i don't really remember why i thought this was funny
19:34amalloyer, hours. not days. jeez
19:34dbaschamalloy: were you trying to pass the reverse turing test?
19:35amalloythe only person who really believed i had become a bot was bbloom
19:36bbloomamalloy: i mean, it would explain your code golf skills
19:36bbloomyou're clearly a search algorithm
19:42cj3kimhow do you know which index the for loop is processing for every cycle? ie if I wanted to know what index (for row[matrix]) was processing?
19:42hiredman~for
19:42clojurebotfor is awesome
19:43hiredmanerm
19:43hiredman~for
19:43clojurebotfor is swanking
19:43hiredmanfeh
19:43hiredmanfor isn't a loop
19:43hiredman(says so in the doc string if I recall)
19:43Glenjamin,(doc for)
19:43clojurebot"([seq-exprs body-expr]); List comprehension. Takes a vector of one or more binding-form/collection-expr pairs, each followed by zero or more modifiers, and yields a lazy sequence of evaluations of expr. Collections are iterated in a nested fashion, rightmost fastest, and nested coll-exprs can refer to bindings created in prior binding-forms. Supported modifiers are: :let [binding-form expr ...], ...
19:43hiredman"List comprehension"
19:43justin_smithcj3kim: the classic is to use map-indexed on the sequence (for [[i e] (map-indexed identity elements)] ...)
19:44justin_smithwhere i will be the number, e the element
19:44cj3kimoh :[
19:44hiredmanjustin_smith: identity doesn't work
19:44Glenjaminalthough if your for is simple, you're probably better off doing the work in the fn passed to map-indexed
19:44justin_smithhiredman: oh, it needs two args, sorry
19:44justin_smith(for [[i e] (map-indexed list elements)] ...)
19:45hiredmanhttp://en.wikipedia.org/wiki/List_comprehension
19:45michaniskin(def indexed (partial map-indexed vector))
19:45cj3kimthank you
19:46hiredmanthat use of map-indexed is also vaguely amusing, because map-indexed was created because there was some contrib function that created indexed sequences
19:46hiredmanand people wanted it in core, but rich hated the idea of constructing pairs when you are just going to rip them apart again
19:47amalloyhiredman: named indexed, in fact
19:47hiredmanit is a hilarious cycle
19:47hiredmanmaybe ridiculous cycle would be a better name
19:47amalloyhttp://clojuredocs.org/clojure_contrib/clojure.contrib.seq/indexed
19:49amalloythere is some weird stuff in old contrib
19:49michaniskinit's something you need to do sometimes, deal with it lol
19:50hiredmanif you don't give people a way to do what they want easily, even if it is inefficient, they are just going to go out of their way to do it and complain about the difficulty
19:50dbaschhiredman: hence pmap :P
19:51amalloymap-vals being hiredman's favorite example of this, i would think
19:52hiredmanamalloy: there are too many examples of this in clojure to pick a favorite
19:52justin_smithmichaniskin: fyi, I just benchmarked w/ criterium, and vector takes 3 times as long as list in a test case where I just add the results (vectors are high overhead for small collections)
19:52justin_smithhttps://www.refheap.com/87634
19:53michaniskinjustin_smith: vectors are nice though because using things like indexed in macros, you don't want to inadvertently evaluate the items in there
19:55michaniskinif you emit lists you have to watch out for that
19:58justin_smithmichaniskin: good news is, with hotspot turned on, both run much faster, and the difference is very small
19:58cj3kimjustin_smith: for loop isn't working. could you take a look at the gist and let me know what's up? https://gist.github.com/cj3kim/01279c340d54db9a5caf
19:58justin_smithmichaniskin: https://www.refheap.com/87634 updated with hotspot results
19:59amalloyjustin_smith: that benchmark shows vector being way faster than list, not the other way around
19:59dbaschcj3kim: for is not a loop
19:59justin_smithcj3kim: as mentioned before, it is not a for loop
19:59dbaschcj3kim: you want doseq
19:59justin_smithcj3kim: calling it a loop is misleading
19:59michaniskinjustin_smith: wow, that's a pretty big improvement
19:59cj3kimgot it
19:59cj3kimthank you
19:59dbaschit's unfortunate that for means one thing in math and another in imperative languages
20:00justin_smithcj3kim: calling dimension-index as if it was a function makes no sense
20:00amalloyit's probably mostly the time spent destructuring, not the time spent on actually building the lists/vectors
20:00justin_smiththat should be giving an error
20:00justin_smiththat is not how for works
20:00justin_smith(or doseq for that matter)
20:01cj3kimjustin_smith: i'm very new to clojure and i'm sure I'm committing grave sins
20:01justin_smithnot sins, just invalid function calls
20:01dbaschcj3kim: the important thing here: for creates a lazy sequence
20:01cj3kimgot it
20:02dbaschcj3kim: you don't want a lazy sequence, you want to iterate over something for side effect
20:02dbaschs
20:02justin_smithalso, it looks like, based on your error message, something in your core ns is shadowing the definition of for
20:03dbaschjustin_smith: the error I see is legit
20:03dbaschhe is passing 3 arguments to for
20:03amalloyjustin_smith: yeah, that's a normal error for for
20:03justin_smithoh, never mind
20:03amalloythere's no implicit-do, because you're not supposed to do side effects
20:04justin_smithI thought it had an implicit do, my bad
20:04justin_smithI guess I never bothered trying to put more than one expression in a for
20:04justin_smithodd
20:05dbaschI do that for debugging once in a while, and wrap everything in a do
20:05cj3kimsolved, thanks guys
20:05cj3kimmy background is in oo javascript so clojure has been a mind fuck
20:19Shayanjmhiredman: I know you said not to use pmap - but it's cutting down execution time by 50%
20:19Shayanjm(as opposed to just throwing it into a map. Haven't experimented with a job queue yet)
20:22hiredmanmashing the accelerator to the floor and not letting up goes fast too
20:36tuftmaybe not an efficient way to get somewhere fast, but it does work!
20:39danielszmulewiczIs there not a built-in map that prunes nils? Is that a bad design idea?
20:39hiredman,(doc keep)
20:39clojurebot"([f coll]); Returns a lazy sequence of the non-nil results of (f item). Note, this means false return values will be included. f must be free of side-effects."
20:41danielszmulewiczhiredman: Oh, nice. Am I being disingenuous if I ask why does f has to be free of side-effects?
20:42amalloydanielszmulewicz: "must be free of side effects" has been sprinkled around the clojure.core docstrings as seasoning
20:43danielszmulewiczamalloy: Exactly my point.
20:43danielszmulewicz(inc amalloy)
20:43lazybot⇒ 135
20:43danielszmulewicz(inc hiredman)
20:43lazybot⇒ 48
20:43amalloyit's not any more true for keep than it is for map, which is to say you should be careful with side effects as always, but nothing drastic will happen if you ignore that warning
20:45danielszmulewiczamalloy: Very true. The docstrings were always throwing me off. What? I can't do that? But it is exactly what I need! Now I just ignore them, but like you say, act with caution.
20:49danielszmulewicz,(false? nil)
20:49clojurebotfalse
20:49danielszmulewicz,(if nil "ee" "rr")
20:49clojurebot"rr"
20:49danielszmulewiczjeez
20:49danielszmulewiczor should I say wat?
20:56rplacadanielszmulewicz:
20:56rplaca,(true? "hello")
20:56clojurebotfalse
20:57rplaca,(if "hello" "ee" "rr")
20:57clojurebot"ee"
21:01danielszmulewiczrplaca: exactly.
21:01rplacaalso:
21:01rplaca,(nil? false)
21:01clojurebotfalse
21:02danielszmulewiczrplaca: to be included in a wat series
21:02amalloydanielszmulewicz: true? and false? ask "is this the boolean true [or false]", not "would this be treated as truthy or falsey in a boolean context?"
21:02rplacatrue?, false? and nil? are equality predicates not thuthiness predicates
21:02amalloyyou're apparently looking for ##(doc boolean)
21:02lazybot⇒ "([x]); Coerce to boolean"
21:02rplaca*truthiness
21:03danielszmulewiczrplaca: all correct, but still not friendly.
21:04rplacadoesn't seem to difficult to me. nil and false are falsey and everything else is truthy
21:04gfredericksdanielszmulewicz: what would you use a truthy? function for?
21:04danielszmulewiczhttp://langnostic.blogspot.co.il/2013/05/truthy-and-falsy-vs-explicit.html
21:04amalloydanielszmulewicz: you'd *really* be saying "wat" if (= true x) gave different results than (true? x)
21:04rplacaturns out to be what you want almost all the time in idiomatic code
21:05amalloythis is just a case of "gosh, i'm asking a question different than the one i meant to, and the computer is answering the question i'm actually asking"
21:05danielszmulewiczThat is true.
21:05gfredericksI guess boolean == truthy?, and not == falsy?
21:06gfredericksso we already have them
21:06gfredericksboolean isn't strictly very useful though
21:07gfredericksI keep using it where I don't quite need to
21:07danielszmulewiczI like the "non-conclusion" of the author of this post: http://langnostic.blogspot.co.il/2013/05/truthy-and-falsy-vs-explicit.html
21:09rplacaIt should be noted that in his empty list example, the idiomatic clojure would be (yay-nay (seq '()))
21:09gfredericksclojure's truthiness violates the zero-one-infinity rule
21:09amalloygfredericks: aha, but without boolean how could we write pithy truthiness examples? ##(group-by boolean [true false () nil {} "" 0])
21:09lazybot⇒ {true [true () {} "" 0], false [false nil]}
21:09gfredericksamalloy: w000h pith!
21:10gfrederickstest.check has an alternate truthiness paradigm internally
21:10gfrederickshttps://github.com/clojure/test.check/blob/master/src/main/clojure/clojure/test/check.clj#L29-32
21:11danielszmulewiczThe more I learn about Haskell, the more I'm drawn to it. So appeallingly clean and logical.
21:14amalloygfredericks: that is weird as heck. it's hard to imagine it being used in a way that doesn't make it hard to write tests for which returning (not throwing) exceptions is the expected behavior
21:14rplacagfredericks: did Reid get that from quick-check or did he do it to fit what he was doing?
21:15ybit2https://github.com/swannodette/om/wiki/Conceptual-overview
21:15ybit2"""Functional programming is not a silver bullet but its emphasis on unadorned data is a guiding light. No models."""
21:15ybit2would someone mind explaining this?
21:16rplacagfredericks: oh - but you don't *always* have to use that, do you?
21:16ybit2https://github.com/heath/treemap/blob/master/app/models/trees.coffee
21:16ybit2i'm not validating the data passed around
21:17oskarkvybit2 what is it that you don't understand, about that quote? :P
21:19oskarkvI'm going to bet, but ybit2 you might wanna watch this http://www.infoq.com/presentations/Value-Values
21:19ybit2i'm not entirely sure why you wouldn't need models, i think the answer for "what goes in its place" is "persistent data structures"
21:19oskarkvbed* :P
21:19gfredericksamalloy: that's my reaction too, but considering that the tests are supposed to be predicate-like, I don't think there's any realistic use for that
21:20gfredericksor at least wrapping it in boolean is an easy workaround
21:20gfredericksrplaca: it's an internal function, the user doesn't use that at all; but amalloy is right that if your test returns an exception it will be misinterpreted
21:22rplacaahh, interesting
21:22gfredericksit's exactly as inhibiting as if (is (Exception. "")) fails
21:23oskarkvybit2 I'm not entirely sure about the "No models" thing. :P It leaves much to the imagination.
21:24ybit2hah :)
21:24ybit2he was saying that facts have "set" methods
21:24ybit2i'm so glad that was a joke :)
21:24oskarkvhehe yeah
21:24gfredericksInteger#setPositive
21:25amalloygfredericks: i'm really surprised that someone who wrote a monad-based testing library would do that. like, surely it's possible to build an Either Result Failure, and know the difference between (Left (Exception.)) and (Right (Exception.))
21:26gfredericksamalloy: I actually wrote that function, but was just refactoring some logic that was already there; but yeah I agree
21:26gfredericksI was thinking of making a microlibrary with that the other day
21:26gfredericks,(defrecord Either [val ex])
21:26clojurebotsandbox.Either
21:27gfrederickswait that doesn't work :P
21:27gfredericks,(defrecord Either [val ex?] clojure.lang.IDeref (deref [_] (if ex? (throw val) val)))
21:27clojurebotsandbox.Either
21:28gfredericks,(defmacro eitherly [ex-class expr] `(try (Either. ~expr false) (catch ~ex-class e# (Either. e# true))))
21:28clojurebotgfredericks: Pardon?
21:28gfredericksclojurebot: fine.
21:28clojurebotCool story bro.
21:29reiddrapergfredericks: amalloy: one of you mind filing an issue?
21:29gfredericksamalloy: dangit now look what you did
21:30reiddraper:D
21:30gfredericksreiddraper: should we have a whole namespace with some Either functions?
21:30amalloygfredericks: it's either that or nothing
21:31reiddraperI agree that returning an exception should not count as a failure
21:32gfredericksamalloy: MULTIMONADIC PUN
21:33amalloyforever $ putStrLn "lol"
21:36blur3dhas anyone had problems with maps/deref working properly in async/go blocks?
21:36blur3dactually.. let me update some dependancies first
21:37hiredman~anyone
21:37clojurebotJust a heads up, you're more likely to get some help if you ask the question you really want the answer to, instead of "does anyone ..."
21:38blur3dhiredman: can you rephrase the above into an example message?
21:38hiredman"I got error message X, what am I doing wrong?"
21:39blur3dsure, but in this case there is no error
21:39amalloyblur3d: "when i do X in a go block, Y happens, which makes me think something is wrong with deref"
21:39danielszmulewicz"Thruthiness" is not a thing. It is subjective and language-dependent. Logical truth is objective and can be reasoned about without intermediate or underlying implementation details. That's what bothers me.
21:39blur3dand it is likely a dependancy bug
21:39hiredman"I have problem X, what am I doing wrong?"
21:40blur3dnot sure I agree still, but let me check dependancies before I try again
21:40hiredmanhaving problems with X is the general state of programming, if you want to really discuss things you need to be more specific
21:41hiredmanthe most specific being a pastebin of code and a description of the problem you have with it
21:42amalloyhiredman: i feel compelled to come up with more specific problem statements
21:43hiredmanamalloy: huh?
21:43amalloy"here is a snapshot of a VM; if you boot it up and do xyz, you'll encounter problem abc"
21:43amalloy(more specific than a pastebin of some code)
21:44hiredmanamalloy: the purpose of the pastebin of code is so others can read it, not execute it
21:44hiredmanI've never tried to read a vm to determine what will happen when I boot it
21:48hiredmanoh man, I just had an idea
21:49hiredmanimagine an irc room for writers, who are, you know, working on their prose
21:49gfredericksdanielszmulewicz: truthiness is how dynamically typed languages deal with the possibility of arbitrary objects being used in a condition
21:50hiredmanand they never share what they have actually written for review, they just sort of trade vague descriptions of their work to see what others think
21:50gfredericksdanielszmulewicz: the only way to avoid partitioning things into truthy and falsy is to throw an exeception when non-booleans are used
21:51hiredman"I have this chapter, it is written in the third person, but I don't think it works, what should I do?"
21:51hiredman"have you tried showing and not telling?"
21:52gfredericks"does anybody here have experience with alternating between first-person and third-person each chapter?"
21:52hiredman"I killed my pov character, but there is more story to tell, what do I do?"
21:54caternhaha
21:54amalloy"i've been practicing by reading moby dick, and i think it would be better without the whale. can someone help me do that?"
21:54catern"Whenever I read one of my chapters I get a NoPlotFoundException, can anyone help?"
21:55gfredericksamalloy: "you thinking about it all wrong"
21:56danielszmulewiczgfredericks: Very interesting. Truthiness is a property then, not a value. When it is encoded in a type, you don't need to infer that property. I'm just wondering how more convenient that is in practice. I wish people with experience with Haskell could weigh in.
21:56rplacadanielszmulewicz: thuthiness may not be a thing but defining in a way that fits with the other paradigms of the language can lead to cleaner, more readable code
21:56gfredericksdanielszmulewicz: well statically typed languages avoid the issue altogether since they can enforce booleans-only at compile time
21:56gfredericksdoes scala do that?
21:57hiredmanwriting prose continues to be my favorite analog for writing code
21:57rplacadynamic laguages could do that to (just like Clojure won't do + except on numbers)
21:57amalloydanielszmulewicz: haskell doesn't really care about truthiness, because using booleans is not super-common; you just pattern-match on stuff
21:58rplacabut everyone would just be annoyed by it :)
21:58amalloyBool and if aren't language built-ins; the former is just `data Bool = True | False`, and if is just `if :: Bool -> a -> a -> a; if True t _ = t; if False _ f = f`
21:59amalloy(well, it's not *really* that, because of the if/then/else syntax. but it could be)
22:00danielszmulewiczOne thing is for sure: truthiness is not spread across dynamic languages in a uniform way, which means that in practice you need to remember language-specific things when dealing with conditions. Annoying.
22:01rplacadanielszmulewicz: true, but it's more important that it fit the paradigm of the specific language.
22:01rplacaand it's not *that* hard to remember if you're writing more than a few lines of code in the language
22:02amalloyif every language were the same, they'd all be the same. what fun would that be?
22:06danielszmulewiczamalloy: I'm still stuck in the fantasy of the "ultimate" language. I should get over it...but only after learning Haskell :-)
22:11geardevis a multi-method kind of like pattern matching in haskell?
22:11gfrederickswhat they don't tell you is that after learning haskell you have to start wanting to learn idris
22:11gfredericksgeardev: it has some overlap; multimethods support inheritance in a couple ways too
22:12gfredericksanother big difference is that multimethods are open
22:12danielszmulewiczgfredericks: spot on. Very true. Dependent types is the next thing.
22:12danielszmulewiczgfredericks: there's no end.
22:13geardevmultimethods are like pattern matching, but they also have inheritance
22:14gfredericksactually any similarity to pattern matching is pretty shallow
22:17Frozenlockbbloom: I updated cljs for a project and I get weird errors which seem related to metadata. Do you know if there was some mentions of problems for metadata recently? (say since 0.0-2173)
23:23halogenandtoastIf anyone is feeling particularly generous, I’m trying to write a game in which cards are dealt to players but I can’t seem to get the logic right. Currently I get “clojure.lang.Cons cannot be cast to clojure.lang.IF” at I think line 57 of https://gist.github.com/halogenandtoast/58cf169f271d49f69005 but haven’t been able to figure out why. I bet there are a number of things I’m doing wrong so any help would be
23:23halogenandtoastmuch appreciated.
23:24trptcolin,(doc update-in)
23:24clojurebot"([m [k & ks] f & args]); 'Updates' a value in a nested associative structure, where ks is a sequence of keys and f is a function that will take the old value and any supplied args and return the new value, and returns a new nested structure. If any levels do not exist, hash-maps will be created."
23:25trptcolinhalogenandtoast: update-in wants the thing where you have `new-hand` to be a function
23:25trptcolinthat’s what the “clojure.lang.Cons cannot be cast to clojure.lang.IFn” error msg is trying to tell you
23:26halogenandtoasttrptcolin: makes sense.
23:27halogenandtoastit almost works now, the conj doesn’t really like my values but I can work with that.
23:28halogenandtoastswitched conj to into, much better
23:29halogenandtoastThanks trptcolin
23:29trptcolinhalogenandtoast: sure.
23:29halogenandtoastI feel like most of what I wrote could be more succint, but I’m just not there yet.
23:31trptcolinyeah, if you wanted you could probably collapse those 3 lines with the `let`s into 1 with update-in, something like (update-in state [:players player-number :hand] into cards)
23:32halogenandtoastYeah the let for the hand isn’t used.
23:32halogenandtoast(update-in state [:players player-number :hand] #(into cards %))
23:34trptcolinah right you want cards first
23:34halogenandtoastAt least I think I do, the whole functional aspect of this is warping my brain.
23:35trptcolinnice. it gets easier
23:37halogenandtoastI’d imagine. I figured this would be a good exercise to start understanding clojure.
23:39trptcolincool, yep