#clojure logs

2014-12-27

01:02sova(* 2 3)
01:02clojurebot*suffusion of yellow*
01:02sovaHahah
01:02pcnThat makes me so happy
01:02pcnLet's everyone get a watch
01:03pcnan i ching calculator watch
01:03sovaclojurebot can perceive colors
01:03pdkafter that i'm feeling pretty suffused
02:24TEttinger(doc map)
02:24clojurebot#<AccessControlException java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessDeclaredMembers")>
02:24TEttingerhiredman, any ideas on what's causing that?
02:38hiredmanI moved the sandbox over to a new host, upgraded the version of clojure to the latest 1.7-alpha, looks like 1.7 uses some more permissions when just loading the clojure runtime
03:20profilWhy does a swap! with a map return the entire atoms value? just like this https://clojuredocs.org/clojure.core/swap!#example_542692d5c026201cdc32709f
03:21thearthurprofil: I'm under the impression that the return value of swap! is only ever the contents of the atom in question
03:21thearthur,(doc swap!)
03:21clojurebot"([atom f] [atom f x] [atom f x y] [atom f x y & ...]); Atomically swaps the value of atom to be: (apply f current-value-of-atom args). Note that f may be called multiple times, and thus should be free of side effects. Returns the value that was swapped in."
03:22thearthurthe reason it does this (if im understanding yoru queston) is do you can thread the swap through other expressions and have them use the new value
03:23thearthur(-> my-atom (swap! assoc :a 1) :a inc dec)
06:20__cskksc__:q
06:27__cskksc__It is possibly a noob question. Can I use (reset! some-atom @other-atom) in a fn after (for ...) ? So in all (fn (for ....) (reset! ....))
06:27__cskksc__It does not seem to work. But if do a reset by itself in repl, it works fine.
06:29thhellerfor is lazy, probably better to doseq if you don't need the result
06:31__cskksc__Ah, thanks so much. It worked.
06:32__cskksc__Had'nt considered the laziness of (for)
08:12SagiCZ1bbloom: really like your article about Code Density, I am in the situation you describe and I am glad I am probably not as stupid as clojure makes me feel sometimes
08:15luxbockSagiCZ1: link to article?
08:15SagiCZ1http://www.brandonbloom.name/blog/2013/06/24/code-density/
08:16luxbockthanks
08:56hellofunk SagiCZ1: i liked that article but i feel like it took me about twice as long to process reading it as compared to, say, a 100K line Java project
09:02perplexammmh..
09:33__cskksc__I'm getting an error between for and doseq. Can anyone please help? http://pastie.org/9800710
09:34justin_smith__cskksc__: well, you won't get the error with for, because for won't even run the code, since the result isn't used
09:36justin_smith__cskksc__: it seems like somewhere your [] got turned into a (), and you can do assoc-in on a ()
09:37__cskksc__Okay yeah it will create a lazy sequence. for works fine in repl though. So i thought if I force eval using doseq it'll work.
09:37justin_smithI think it's because somewhere grid or next-grid is being turned into a lazy-seq where it used to be a vector
09:37justin_smithyou can't assoc-in on a lazy-seq
09:38justin_smiththat's what that error is saying
09:38__cskksc__justin_smi: Thanks :) .Getting back to it.
09:39justin_smithalso, this style of code isn't the best use of clojure. I think you'll find that rewriting to a functional style will be more clear, and also faster.
09:40__cskksc__You mean I could do it without a atom ?
09:40justin_smithright, and without globals in general
09:42justin_smithI don't see anything in your code that would turn the game state into a lazy-seq, but I still think that is the cause of the error
09:43__cskksc__ah okay, ill try doing it without game-state in var.
09:43justin_smith__cskksc__: the translation will likely be tricky at first, you may want to solve your current issue before undertaking it
09:45__cskksc__justin_smi: yeah. im very new to clojure and functional programming in general :)
09:46justin_smiththe general "big picture" of it is that you translate the code so that any globals accessed become arguments to the function, and any globals modified become part of the return value
09:47justin_smithand then you'll often end up using higher order constructs like map or reduce to describe a series of updates, propagating the results via return value
09:50__cskksc__yeah
09:51justin_smithalso, as a little stylistic thing, a cond with only one condition is better expressed as "when", and a cond with only two conditions is better expressed as "if"
09:54hellofunkjustin_smith: except that with if there is one test, while a cond with two exprs can have 2 different tests, no?
09:55justin_smithhellofunk: I am referring to __cskksc__ 's pasted code, where he uses (cond (q? x) y :otherwise z)
09:55hellofunkjustin_smith: ok
09:55justin_smithhellofunk: of course for that generalized case you still want cond, but he never uses it that way
10:13__cskksc__justin_smith: Yeah you're right. an 'if' makes more sense there.
10:16SagiCZ1i want to have two optional parameters with zero default values, is this correct?
10:16SagiCZ1[x & {:keys [mag acc] :or {mag 0 acc 0}}]
10:17luxbockSagiCZ1: yep
10:17justin_smithSagiCZ1: that works, but seriously consider not using varargs keyword params, they are tricky to use
10:18justin_smithit's much easier to just take an optional map, that makes composing with other functions easier
10:18SagiCZ1i think i saw this kind of usage all over seesaw for example
10:19SagiCZ1isnt this an optional map?
10:19justin_smithSagiCZ1: it's optional key value pairs
10:19justin_smith[x & [{:keys ...}]] would be an optional map
10:19SagiCZ1i see.. then the user has to put { } around the params right?
10:20justin_smith&((fn [& {:keys [a b]}] (+ a b)) :a 1 :b 2)
10:20lazybot⇒ 3
10:20justin_smith&((fn [& [{:keys [a b]}]] (+ a b)) {:a 1 :b 2})
10:20lazybot⇒ 3
10:20justin_smithexactly
10:20justin_smithbut keeping things in a map is actually convenient in many ways
10:21SagiCZ1cool.. didnt know its better
10:21hellofunkSagiCZ1: plus if you want defaults, you can just merge the arg map onto a defaults map, any args provided will overwrite the defaults
10:23SagiCZ1hellofunk: and i would do that in the funciton body right?
10:23hellofunkSagiCZ1: yes
10:24SagiCZ1thanks
10:24hellofunkSagiCZ1: you might be able to destructure it as well, but i think the body is easier personally
10:29SagiCZ1how does this work?
10:29SagiCZ1&(#(read-string (str 2 \r %)) "101010101")
10:29lazybot⇒ 341
10:30SagiCZ1&(#(read-string (str 2 %)) "101010101")
10:30lazybot⇒ 2101010101
10:30Bronsa,2r101010101
10:31clojurebot341
10:31SagiCZ1ohh..
10:31BronsaSagiCZ1: it's the radix syntax
10:31SagiCZ1so its a clojure literal?
10:31Bronsa2rXXX means XXX in base 2
10:31Bronsayeah
10:31SagiCZ1thats clever
10:31Bronsa3r23
10:31Bronsa,3r23
10:31clojurebot#<NumberFormatException java.lang.NumberFormatException: For input string: "23">
10:31Bronsa,3r22
10:31clojurebot8
10:31Bronsaetc
10:31SagiCZ1thank you
10:32Bronsathere's also
10:32Bronsa,1e4
10:32clojurebot10000.0
10:32hellofunkand, this time of year, it's nice to catch up with r&r too
10:32hbccbh,4r3e2
10:32clojurebot#<NumberFormatException java.lang.NumberFormatException: For input string: "3e2">
10:32hbccbh,4r3.2
10:32clojurebot#<NumberFormatException java.lang.NumberFormatException: Invalid number: 4r3.2>
10:33masnun,(+ 1 1)
10:33clojurebot2
10:33justin_smithit's too bad that doesn't work
10:33justin_smith,(* 4r32 0.1)
10:33clojurebot1.4000000000000001
10:33justin_smithnot as nice
10:33clojurebotNo entiendo
10:35tephrais it worth getting clojure coockbook given that I already have programming clojure?
10:35SagiCZ1cockbook?
10:36tephraoops soory
10:36hellofunktephra: each clojure book is a different point of view. absorb them all if you have time and interest
10:38tephrahellofunk: thanks, someone told me that it was unnecessary but given that I get it for free i think it should get it then :)
10:39SagiCZ1tephra: cant harm
10:39hellofunkand how do you get it for free? tephra
10:40tephragot a free ebook from oreilly
10:41hellofunktephra: you have the oreilly clojure book by chas and christophe right?
10:41luxbockhttps://github.com/clojure-cookbook/clojure-cookbook
10:42tephrahellofunk: yeah programming clojure right? got it when we used clojure in school a year ago, chas, brian and christophe
10:42SagiCZ1clojure in school? wow
10:42tephraoh it's clojure programming
10:43SagiCZ1yeah its a diffrence
10:43tephrayeah i got that one (clojure programming)
10:44SagiCZ1me too.. liked it
10:44tephraSagiCZ1: in our programming language and paradigms course we used it to learn functional programming
10:44SagiCZ1tephra: good teachers then..
10:44tephrayes it's very good
10:45tephraSagiCZ1: yes very good, my latest course is learning distibuted and parallel programming in erlang with joe armstrong :)
10:46SagiCZ1what school is this?
10:46bbloomSagiCZ1: luxbock: glad you guys enjoyed the article! thanks
10:47tephraSagiCZ1: stockholm university
10:47SagiCZ1bbloom: hi, you're welcome!
10:47SagiCZ1tephra: hah maybe i should finish my masters there
10:48hlprmnkySo I'm trying to run a REPL inside a Docker container from library/clojure:latest - I have cider-nrepl 0.8.2 as a dependency in my project and in my ~/.lein/profiles.clj (so, one on each side of the host/container divide)
10:48tephraSagiCZ1: unfortunetly we don't have any comp sci masters
10:48tephra:(
10:48hlprmnkyboth are running Leiningen 2.5.0, on Java 1.7.0 (the minor versions of the JDK do differ)
10:48SagiCZ1what about cybernetics?
10:48hlprmnkyand when I try to connect, I get this:
10:49hlprmnkyConnecting to nREPL at 127.0.0.1:12345
10:49hlprmnkySocketException The transport's socket appears to have lost its connection to the nREPL server clojure.tools.nrepl.transport/bencode/fn--7462/fn--7463 (transport.clj:95)
10:49hlprmnkyI do know that the REPL session is listening on 12345, and that the port is forwarded to the host (verified with 'docker port')
10:50tephraSagiCZ1: no sorry, the master is in computer and system science but no programming. security, data mining and bussiness inteligence
10:50hlprmnkyThe last time I ran into an issue in bencode it was because I had leiningen 1.x on one side and 2.x on the other, but that's not the case here
10:50SagiCZ1i see
10:50hlprmnkygoogle hasn't been super illuminating, I'm hoping someone else here has been in a similar situation and fixed it. :)
10:50tephraSagiCZ1: I'm thinking of getting my master from Uppsala since they actually do computer science. Just have my bachelor thesis left :)
10:57SagiCZ1tephra: me too, good luck!
10:59tephraSagiCZ1: same! where do you study?
11:02SagiCZ1in Prague
11:29SagiCZ1how can i get and remove random element from a vector?
11:30SagiCZ1,(remove #{3} [1 2 3 3 4 5])
11:30clojurebot(1 2 4 5)
11:30SagiCZ1i need to remove only one.. not all the duplicates
11:31SagiCZ1i will probably have to work with indexes
11:32AimHereWell stepping through the collection with loop/recur is an option here
11:32andyfSagiCZ1: Do you plan to eventually remove all elements from the vector? If so, you could shuffle it, then pop one element at a time from the end
11:32masnun,(set [1 2 3 3 4 5])
11:32clojurebot#{1 4 3 2 5}
11:33andyfefficiently
11:33SagiCZ1andyf: its complicated.. i need to go through the collection one element at a time and decide if i want to keep it or not
11:33AimHere,(set [1 2 3 3 3 3 4 5
11:33clojurebot#<RuntimeException java.lang.RuntimeException: EOF while reading>
11:34AimHere,(set [1 2 3 3 3 3 4 5])
11:34clojurebot#{1 4 3 2 5}
11:34andyfYou can either use the built-in vectors, and then removing an element takes linear time, or use core.rrb-vector, where removing an element can be done in log n time.
11:34hellofunkSagiCZ1: really depends if you are removing from a specific location (index) in the collection or if you are removing based on a predicate
11:35SagiCZ1i dont know how to explain it
11:36hellofunkSagiCZ1: well, index vs. predicate should be a simple decision
11:36SagiCZ1i just need to go through all of the element.. i dont care about order
11:37hellofunksounds like you are removing based on a predicate
11:37hellofunkunless it truly is random
11:37SagiCZ1it doesnt have to be random
11:37AimHereSo each time you pick an element you reduce the number by one? Couldn't you have a map of value counts using frequencies, and just decrease the value of that map by one each time that predicate comes up?
11:38andyfHere is one way to remove an element at a specified index from a vector, returning a vector, taking linear time: (defn remove-elem-i [v i] (vec (concat (subvec v 0 i) (subvec v (inc i)))))
11:38AimHereThen rebuild the collection with some sort of homegrown invert-frequencies function
11:38SagiCZ1AimHere: no, sometimes i decide not to remove the element so the count stays the same, then i need to move on the next element.. as if increasing index by one
11:39AimHereWhat's the main goal here? It sounds like there might be an x-y problem going on
11:39SagiCZ1i am implementing iterative optimization described here http://www.cs.cmu.edu/afs/cs/project/jair/pub/volume4/fisher96a-html/node8.html#SECTION00032000000000000000
11:40SagiCZ1i have a collection of n clusters consisting of some number of points.. i need to go through all the points and try to re-assign them to a different cluster if it would improve the overall cluster fitness
11:45AimHereMy first instinct for something like that would be to use reduce or loop to go through the cluster and rebuild the original cluster without the reassigned ones
11:46SagiCZ1i will try some loop magic thanks for ideas
12:10hellofunkcan unquote-splice be used outside the context of a macro or eval?
12:10justin_smithabsolutely
12:10hellofunki.e. this works: (eval `(~@(list + 1 2 3))) but this does not: (+ `(~@(list 1 2 3)))
12:11justin_smithhellofunk: you just have to use it in a way that makes syntactic sense
12:11hellofunkwell (+ 1 2 3) is valid syntax, so why doesn't (+ `(~@(list 1 2 3))) do as i'd expect?
12:12justin_smithbecause (+ (1 2 3)) isn't valid
12:12justin_smithand that's what you are generating
12:12hellofunkah, i'm getting jumpled in my nesting
12:13justin_smith,(apply + `[1 2 3 ~@[4 5 6]])
12:13clojurebot21
12:13justin_smithnote how the inner coll is spliced into the one above it
12:13hellofunkjustin_smith: i can't use apply since i'm actually trying this on ->
12:13justin_smithOK
12:14justin_smithoutside of eval / macros ~@ can only generate a list
12:14hellofunki was thinking i'd could splice into the parent form
12:14justin_smithright, yeah, outside a macro that's not really going to work
12:19arrdemwhere is there a good writeup on nREPL middlewares?
12:26hellofunkjustin_smith: i guess the issue is that backquote must always be followed by a paren, you cannot use ~@ with a ` alone
12:26SagiCZ1andyf: thank you for that element removing function, i build the algo around that, its nasty but pretty short and works, thanks
12:26SagiCZ1(inc andyf)
12:26lazybot⇒ 16
12:31justin_smithhellofunk: well, paren or some other nesting pair (my example used [])
12:32justin_smith&`[1 2 ~@{:a 0 :b 1}]
12:32lazybot⇒ [1 2 [:b 1] [:a 0]]
12:33justin_smith&`["test" ~@#{1 2 3}]
12:33lazybot⇒ ["test" 1 3 2]
12:38AdmiralBumbleBeea note, O'rielly is offering a free ebook, one of the choices is 'Clojure Cookbook'
12:38AdmiralBumbleBeehttp://post.oreilly.com/rd/9z1zsko8rq94drpmmfel8vj0u6drolp2ihbcme9uljg is the link
12:38maxigasrly?
12:38maxigaswow cool
12:38AdmiralBumbleBeeyes
12:39AdmiralBumbleBeejava performance, the definitive guide is an option too
12:39AdmiralBumbleBeewhich is an excellent book that's helped my clojure programming a lot.
12:40maxigasheh i tried to register and got this
12:40maxigasError: time_in_future.
12:40AdmiralBumbleBeeyeah, it appears to be having issues at the moment
12:40justin_smithyeah, I got that error when I logged in
12:40AdmiralBumbleBeejust refresh
12:40AdmiralBumbleBeeit works eventually
12:42maxigasAdmiralBumbleBee: true
12:42maxigasbut
12:42maxigasAdmiralBumbleBee
12:42maxigashttp://libgen.org/book/index.php?md5=3f6bc98349b3d776640ba6215fc8d9d8
12:42maxigas^^^ clojure cookbook is already liberated by pirates
12:43maxigas:P
12:45klhow does racket compare to clojure?
12:46justin_smithit uses it's own vm - uses less memory, not as fast, is able to tree-shake for generating smaller executables
12:46justin_smithhas less default usage of immutable / persistent datatypes (though it does have them if you look for them)
12:47justin_smithalso, racket is part of a system designed for teaching programming
12:47justin_smithwhile clojure is more pragmatic, industry oriented (relatively speaking)
12:50justin_smithlibrary interop w/ clojure is via the jvm, and is totally transperent (there is no translation / compatibility layer needed), library interop in racket will be with C libs, and requires ffi wrappers
13:16justin_smithhellofunk: here's a weird one ##`{:a 0 ~@[:b 1] ~@[:c 2 :d 3]}
13:16lazybot⇒ {:c 2, :b 1, :d 3, :a 0}
13:16justin_smithhellofunk: to see why it is weird, try taking one of those splices out
13:46SagiCZ1how do i split coll into n equal parts?
13:46arrdempartition
13:46arrdem$grim clojure.core/partition
13:46lazybothttp://grimoire.arrdem.com/1.6.0/clojure.core/partition
13:46SagiCZ1thats splitting it into m n-sized parts
13:48arrdem#(partition (/ (count %2) %1) %2), use a real function if you want to assert that %2 divides (count %1) exactly.
13:48SagiCZ1arrdem: thanks
13:50maxigashmmm Continuous Enterprise Development in Java is not on libgen
13:50SagiCZ1,(#(partition (/ (count %2) %1) %2) 3 (range 10))
13:51clojurebot()
13:57arrdem##(count (range 10))
13:57lazybot⇒ 10
13:58SagiCZ1,(#(partition (/ (count %2) %1) %2) 3 (range 12))
13:58clojurebot((0 1 2 3) (4 5 6 7) (8 9 10 11))
13:58SagiCZ1 ,(#(partition-all (/ (count %2) %1) %2) 3 (range 10))
13:58clojurebot((0 1 2 3) (4 5 6 7) (8 9))
14:00sveriHi, is there a way to evaluate every function of a namespace in cursive when it is connected to a repl? All I found is how to load the complete file and then evaluate every form separately
14:03sveriHm, I just saw that load file does that, seems like I have a different error in my workflow, nevermind
14:12hellofunk##`{:a 0 ~@[:b 1] ~@[:c 2 :d 3]}
14:13lazybot⇒ {:c 2, :b 1, :d 3, :a 0}
14:13hellofunkman how many of these bots do we have for syntax eval.
14:13hellofunk##`{:a 0 ~@[:b 1]}
14:13andyf,(count (available bots))
14:13clojurebot#<CompilerException java.lang.RuntimeException: Unable to resolve symbol: available in this context, compiling:(NO_SOURCE_PATH:0:0)>
14:14hellofunkjustin_smith: so the core clojure reader for syntax takes precedence over the reader macros for syntax quote and unsplicing
14:14andyfsyntax quote is part of the Clojure reader
14:15hellofunkandyf: indeed but the map form is read as having too few args before the splicing of the reader has a chance to do its thing... even though the backquote is actually read before the map
14:16hellofunkjustin_smith: so i concur with you, that is indeed weird
14:17hellofunkdoes anyone regularly run emacs and cider on a running web app on a remote server via ssh?
14:27maxigashttp://libgen.org/book/index.php?md5=e2d9cadb117ce286f7dae2667158ba84
14:27maxigas^^^ Continuous Enterprise Development in Java: Testable Solutions with Arquillian
14:34HamledCan someone explain to me why
14:34andyfmaxigas: Is this relevant to a discussion, or you like to post links to books that have been pirated?
14:34Hamled##(= (short-array [1]) (short-array [1]))
14:34lazybot⇒ false
14:35augustlHamled: see: Java :)
14:35andyfYeah, for the same reason that .equals returns false for those two things in Java
14:35Hamledokay
14:36Hamledhmm
14:36andyfClojure's = is true if two immutable values are equal, or if they are not immutable, then if Java .equals is true for them. There may be a few exceptions to that statement, but I think not many.
14:37maxigasandyf: sorry it was quite offtopic, now that you made me think about it
14:39andyfJava docs for equals method says "The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object"
14:39andyfOther classes can override that default, but perhaps Java arrays do not.
14:41andyfHmm. The docs for the Java Arrays class says that two short arrays are .equals if they are the same length and have equal elements, so now I don't know why you got false ...
14:43justin_smithhellofunk: I avoid lein in production, not to mention cider / emacs
14:43andyfah, (java.util.Arrays/equals ...) would return true, but that is a static method in class java.util.Arrays, not the one that you get from doing regular .equals method
15:05Frozenlockhellofunk: I do. (cider, emacs, running app, ssh.... )
15:08kljustin_smith: thanks for that response re: clojure vs racket there earlier
15:09klHmm. I can't help but feel I'd absolutely love clojure if it was statically typed.
15:10kenrestivo*cough* core.typed *cough*
15:11klkenrestivo: I've not *seriously* looked at it - but is it not a hack, or somehow otherwise badly implemented / ill-advised?
15:12dnolen_kl: it's based on Typed Racket research
15:12klThat *is* interesting
15:14profilthearthur: but it says, "Returns the value that was swapped in.". Shouldnt that mean ":a 1"?
15:14profilthearthur: re swap!
15:23dnolen_kl: The biggest difference between Clojure & Racket is that Clojure is a production oriented language that targets the JVM & JavaScript and goes out it's way to work well on those hosts, with host libraries, and with host tooling. If these platforms matter to you & you like Lisp then the other factors are considerably less important.
16:08augustlanyone using something other than compojure to path match for liberator?
16:08augustlI fancy myself a path matcher that isn't a list essentially a list of regexps :)
16:13heetonHaving trouble doing this idiomatically. How do I update values inside a tree? https://gist.github.com/heeton/aafd06e63bfb847f57f6
16:13heetonI've tried to dig into zippers but am finding them a bit opaque :)
16:17augustlheeton: generally I prefer to not store tree structures as deep data structures matching the tree structure, but store by reference instead. I.e. something like {1 {:type "foo" :children [2 3]} 2 {:type "foo"} 3 {:type "foo" :children [4]} 4 {:type "bar"}}
16:17mearnshneed a pointer getting this macro to expand recursively (see the last cond case). L11 shows the behaviour i'm looking for: https://www.refheap.com/95469
16:17augustlheeton: I like my trees shallow :)
16:19heetonaugustl: not sure how I could simplify my structure unfortunately, any suggestions?
16:19heeton(Massive noob here btw)
16:19heeton(And probably still too stuck in OO mode)
16:20augustlheeton: maybe something like {1 {:type "plots" :children [2 3]} 2 {:type "wat" :contains nil} 3 {:type "wat" :contains nil}}
16:20augustlthe downside is of course that invalid states are representable
16:21TEttinger:pre conditions may be handy
16:21augustlheeton: or if your tree doesn't need to be ordered you can store it as {:plots {1 {:contains nil} 2 {:contains nil}}} and run update-in
16:21augustland assoc-in
16:22heetonThe plots are ordered
16:22TEttingerordered maps may come in handy, there's that lib called ordered
16:22TEttinger$google ordered clojure
16:22lazybot[flatland · GitHub] https://github.com/flatland
16:22heetonTEttinger: thanks, will have a look
16:23TEttingerhttps://github.com/flatland/ordered/tree/develop
16:24mearnshhm, i realize i can just call macroexpand inside my macro
16:24TEttingermearnsh, sounds like wizardry
16:24heetonHypothetically, if I were to reference plots (using a let block or something) and then use update-in on it, will that affect the atom? Or am I creating a copy of the variable or something? (Apologies if naming is slightly wrong)
16:24TEttingerupdate-in returns a new coll
16:24mearnshTEttinger: cf these: https://www.refheap.com/95469 https://www.refheap.com/95470
16:24TEttingerto update an atom, you use swap! or reset!
16:25TEttinger(doc swap!)
16:25clojurebot"([atom f] [atom f x] [atom f x y] [atom f x y & ...]); Atomically swaps the value of atom to be: (apply f current-value-of-atom args). Note that f may be called multiple times, and thus should be free of side effects. Returns the value that was swapped in."
16:25TEttinger(doc reset!)
16:25clojurebot"([atom newval]); Sets the value of atom to newval without regard for the current value. Returns newval."
16:25augustlheeton: well at any point if you read from the index and then tell the atom to write to that index, you're unsafe since the atom might have changed in the meantime
16:25heetonTEttinger: that'll set the value of the overall atom though right? I'm wondering if I can access nodes inside it in the same way
16:25augustls/read from the index/read an index/
16:26augustlfor advanced stuff I would have considered just having some kind of atomic ref and writing my own code that maybe used an executor..
16:26TEttingeryou may want refs if you want to be sure about multiple transactions overlapping
16:26heetonHmm, so I'm really confused then. What's the recommended way of getting to my goal? I've got my application state which has a few pieces of data, one of which is a list of plots. I'd like to update those.
16:27heetonI might just bring plots out to be it's own atom
16:27TEttingerplots as in graves or plots as in graphing calculator stuff?
16:27TEttingeror action movie "plots"
16:28heetonHaha, let's assume graves here :)
16:28heetonActually for keeping track of plants
16:28heetonSo a plot is a map that has some keys like "planted-at" "contains" etc.
16:29TEttinger,(let [state (atom {:plots [[1 2][1 5]]})] (update-in @state [:plots 0 1] inc))
16:29clojurebot{:plots [[1 3] [1 5]]}
16:29TEttinger,(let [state (atom {:plots [[1 2][1 5]]})] (do (update-in @state [:plots 0 1] inc) @state))
16:29clojurebot{:plots [[1 2] [1 5]]}
16:30TEttingeras you can see, it doesn't change after just calling update-in, but...
16:30TEttinger,(let [state (atom {:plots [[1 2][1 5]]})] (swap! state update-in [:plots 0 1] inc))
16:30clojurebot{:plots [[1 3] [1 5]]}
16:30TEttinger,(let [state (atom {:plots [[1 2][1 5]]})] (do (swap! state update-in [:plots 0 1] inc) @state))
16:30clojurebot{:plots [[1 3] [1 5]]}
16:31TEttingerswap! will change the value of the atom at later reads
16:31heetonOk, thanks, will crack on with it :)
16:31TEttingerbut most of clojure's collection fns will return new collections (with shared state for efficiency)
16:32mearnshok, i solved my problem - my code was right, just forgot about macroexpand-all
16:32TEttingeroh, and if you want to add something, you can do something like
16:33TEttinger,(let [state (atom {:plots [[1 2][1 5]]})] (do (swap! state update-in [:plots 2] (constantly [3 4])) @state))
16:33clojurebot{:plots [[1 2] [1 5] [3 4]]}
16:33TEttinger,(let [state (atom {:plots [[1 2][1 5]]})] (do (swap! state update-in [:plots 3] (constantly [3 4])) @state)) ;; I can't remember if this works, indexes that are larger than the size
16:33clojurebot#<IndexOutOfBoundsException java.lang.IndexOutOfBoundsException>
16:49dnolen_is it possible to set the plugins classpath for leiningen?
16:49dnolen_curious about running AOTed plugins
16:50dnolen_update my exploration on making cljsbuild run faster http://swannodette.github.io/2014/12/22/waitin/
16:50dnolen_basically you can make cljsbuild start 5X faster w/ all my tweaks
16:50dnolen_so 1 second to run (and do everything) instead of 5.5 seconds
17:00hellofunkcool stuff. i've never been sensitive to a few extra seconds that others complain about with clj and now you say cljs, but dramatic engineering is still captivating to ponder
17:10justin_smithBronsa: maybe you can provide some more insight to this SO question about a failed type annotation? It clearly has something to do with the destructuring, but it would be cool to know more of the details of why that failure happens. http://stackoverflow.com/questions/27671638/why-is-this-type-annotation-failing
17:12justin_smithaugustl: that structure is known as an adjacency list representation by the way, and it is great because it bridges the gap between cyclical data structures and immutable data, without any laziness hacks
17:13Bronsajustin_smith: I don't have a SO account but ^double is an array type hint, [4 5 6] is not an array
17:13Bronsajustin_smith: invoking it as (dot3 (double-array [4 5 6]) (double-array [1 2 3])) would do what he expects
17:14dnolen_hellofunk: the startup time is fine for REPL based stuff, it's serious bummer for tooling - things you run at the command line
17:15Bronsajustin_smith: uhm no, nevermind. let me read that better
17:15justin_smithBronsa: actually it doesn't
17:15justin_smithI tried that first :)
17:15hellofunkdnolen_: is the performance boost to lein cljsbuild auto for speeding up each automatic compilation? So if it took 1 sec before when you save a file, now it takes much less?
17:16justin_smithI think it is some compiler optimization that kicks in (the IFN$OOD inner class) but the destructuring makes it compile in a faulty way?
17:16Bronsajustin_smith: I can't reproduce on my repl?
17:16dnolen_hellofunk: this is about speeding up incremental compilation, that's already fast
17:16dnolen_hellofunk: it's been fast forever
17:16justin_smithBronsa: with warn-on-reflection and hotspot both enabled?
17:16dnolen_hellofunk: "this is NOT about speeding up incremental compilation"
17:17Bronsajustin_smith: ah.
17:17Bronsajustin_smith: it's a bug I fixed that's committed in 1.7 I believe
17:17justin_smithBronsa: https://www.refheap.com/95471
17:17Bronsajustin_smith: https://github.com/clojure/clojure/commit/85169b785c5dd59e89c0bd12600eebe5f6172874
17:17justin_smithaha, cool
17:17Bronsathat would explain why in my repl it works fine
17:18Bronsajustin_smith: http://dev.clojure.org/jira/browse/CLJ-887 yup the error seems the same
17:19justin_smithvery nice to have a decent explanation, thanks
17:19justin_smith(inc Bronsa)
17:19lazybot⇒ 81
17:20justin_smiththat is way too low
17:20justin_smith(inc Bronsa)
17:20lazybot⇒ 82
17:23Bronsai wounder how hard it would be to make c.c/destructure understand array type hints
17:23Bronsawonder*
17:23Bronsaprobably not that hard
17:23justin_smiththat would be nice
17:36SagiCZ1how do i make an inverse matrix and matrix determinant in incanter?
17:37SagiCZ1or should i use clojure.core.matrx?
17:43SagiCZ1oh i guess inverse is called solve in incanter.. so silly
18:05gfrederickshaving a hard time not getting this error when switching to java 8; look familiar?
18:05gfredericksUnable to resolve classname: ..proxy$java.lang.Object$SignalHandler$d8c00ec7
18:06Bronsagfredericks: no idea but try applying http://dev.clojure.org/jira/browse/CLJ-979
18:06justin_smithgfredericks: I have never seen that
18:07gfredericksI wonder if this is a problem with namespaces named .
18:09justin_smithgfredericks: I was always surprised that a namespace named . would even work
18:09gfredericksturning off my user profile made it work so that might've been it
18:09gfredericksthe "..proxy" part made me wonder
18:18TEttingeroh my god do I need to make another gfredericks meme
18:18augustltrying out bidi for the first time. Why does (match-route ["/foo/bar" :bar "/" :root] "/foo/bar") return {:handler :bar} and (match-route ["/" :root "/foo/bar" :bar ] "/foo/bar") nil? I expected both to return {:handler ;bar}
18:22augustlFigured it out. Seems the vector should only have two items in it.
18:24justin_smithyeah, it looks like for multiple routes you want a vector with parent on the left, and a tree (map) of all child routes on the right
18:27dnolen_cfleming: fwiw, just encountered the issue again with cljs/closure.clj, all core symbol cannot be resolved
18:33TEttingergfredericks: justin_smith: https://dl.dropboxusercontent.com/u/11914692/gfredericks.png was the first, now there's https://dl.dropboxusercontent.com/u/11914692/gfredericks_on_namespaces.png
18:33Kristienlol
18:34justin_smith(inc TEttinger)
18:34lazybot⇒ 34
18:34TEttingergfredericks is like the corner case detective
18:35TEttingerif there is a minute crack in the facade that is reliable software behavior, gfredericks will apply a liberal dose of plastic explosive
18:37Bronsa(inc TEttinger)
18:37lazybot⇒ 35
18:40akkadthank you all for making this language soo welcoming
18:40HamledIs there something about the way I've written this test that would cause it to pass even though its condition definitely fails (I can see that when I evaluate it directly) http://hastebin.com/fumiwavixo.clj
18:40justin_smithHamled: you don't call is
18:40justin_smithonly test/is can cause failures
18:41Hamledoh lol of course )
18:41Hamledthanks
18:41TEttingerakkad, glad the community is welcoming! so, you're welcome!
18:41justin_smithvery common mistake, there is a lein plugin called eastwood that will tell you when you have problems like that
18:41akkadcompared to years of #lisp yes. :P
18:41TEttingerheh
18:41TEttingerwho makes eastwood again?
18:41Hamledjustin_smith, ah cool I think I saw eastwood before but wasn't sure what it was for
18:41augustlakkad: just making up for the bad error messages, that's all
18:42Bronsa(inc andyf) ;; TEttinger
18:42lazybot⇒ 17
18:42justin_smith"you're more welcoming than #lisp" is kind of like "it tastes better than earwax"
18:43TEttinger(inc justin_smith)
18:43lazybot⇒ 163
18:43Hamledoh lol I have eastwood in my plugin list I just never thought to use it :D
18:43TEttingerdamn your karma has gotten significant
18:49justin_smithsomehow it has. most of the people I end up helping don't even know how karma works
18:51cflemingdnolen_: Ok. Closing and reopening the file doesn't work, right? Are other symbols from other files resolved correctly?
18:51dnolen_cfleming: yes they are
18:52dnolen_cfleming: and no closing/reopening doesn't work
18:52cflemingdnolen_: Well that's really weird. Next time it happens can you send a screenshot, and I'll see if I can see anything unusual?
18:52dnolen_cfleming: sure thing
18:53augustlliberator is such awesome, wow
18:55SagiCZ1justin_smith: how does karma work? i started to feel stupid inc'ing everyone who helped, so i rarely do it now which makes me feel a little bad.. like not apprecienting the help enough
18:58justin_smithSagiCZ1: it's totally informal
18:59justin_smithnothing to feel bad about, or to gloat about
18:59SagiCZ1so its just a little fun thing...
18:59justin_smithSagiCZ1: meant it as in they don't even use the karma commands
18:59justin_smithyeah
19:00SagiCZ1oh so otherwise there is something like karma on IRC? maybe thats why it doesnt confuse me
19:01SagiCZ1i started with IRC only because of #clojure
19:01justin_smithit's a convention, various channels have bots that keep track of informal karma
19:01justin_smithusually via nick++
19:02SagiCZ1i see
21:00thearthur,(let [a (atom 0)] (swap! a inc))
21:00clojurebot1
21:01thearthurprofil: yes you are right the atom it's self is not returned by swap. Could you link ot the context where it was seeming to do so
21:20gfredericksjustin_smith: my java 8 . problem was apparently caused by putting (ns .) in my [:repl-options :init]
21:20gfredericksswapping it out for (create-ns '.) fixes it
21:21gfredericks(YOLO)
21:21justin_smithhaha
21:48gfredericks,(try (re-pattern "\\R") :java-8 (catch Exception e :java-7))
21:48clojurebotgfredericks: No entiendo
21:48gfredericks&(try (re-pattern "\\R") :java-8 (catch Exception e :java-7))
21:48lazybotjava.lang.SecurityException: You tripped the alarm! catch is bad!
21:48gfredericks,(re-pattern "\\R")
21:48clojurebot#"\R"
21:48gfredericks&(re-pattern "\\R")
21:48lazybotjava.util.regex.PatternSyntaxException: Illegal/unsupported escape sequence near index 1
22:13richardlevanHey guys, I’m trying to learn core.async. In a tutorial, I can do the following in a let statement:
22:13richardlevan(let [c (chan)]
22:13richardlevan(go (>! c "hello"))
22:13richardlevan(assert (= "hello" (<!! (go (<! c)))))
22:13richardlevan(close! c))
22:13richardlevanBut if I say (def c (chan)) then (go (>! c “hello”)) it fails. Can someone explain why?
22:15nuwanda_what do you mean by fails?
22:15richardlevanI get a big stack trace as a result
22:16richardlevanI have [org.clojars.trptcolin/core.async "0.1.242.1"] in :dependencies in my project.clj, and I used (require '[clojure.core.async :as async :refer :all]) to get core.async
22:19richardlevanHm, seems pretty quiet here. Anyone know where else I could get help?
22:23richardlevanHey I don’t use IRC often. Am I doing this right? Why are people joining and leaving but no one is speaking?
22:24andyfSometimes people leave automatically because their computer shuts down, or their network connection gets disconnected. They aren't necessarily doing anything manually for it to happen. Same for joining -- for some people it happens automatically when their network connection is restored.
22:24richardlevanoh ok thanks
22:24andyfNot everyone joined to the room is paying attention right now. Most probably are not.
22:25richardlevanDo you know a place where I’d be more likely to get help for my question?
22:25andyfHere, next week :)
22:25richardlevanhaha, yeah I guess Saturday night is a bad time :P
22:25andyfWell, Saturday night not always so much like this -- but this is the week between Christmas and New Year's, so lots of people are on unusual schedules and doing other things.
22:26richardlevanAh yeah that makes sense too. Cool, I’ll come back here again in the future
22:26andyfYou could send a message to the Clojure Google group, or if there is one specifically for core.async, there.
22:27andyfYou are more likely to get help if you include as many details about what you are doing, and error messages you are seeing, as you can.
22:27richardlevanOk nice, thanks for the tips
22:27andyfand also if you can break it down to a minimal case that gives the same error.
22:31ToxicFrogrichardlevan: for future reference, don't just say "I get a stack trace". Pastebin the whole stack trace somewhere and link it, and possibly mention what the exception that caused it is named.
22:32ToxicFrogrichardlevan: in my case, both of those examples work fine, as long as I type the second one in from scratch.
22:32ToxicFrogrichardlevan: if I copy-paste it, it fails because you use “hello” instead of "hello".
22:36richardlevanToxicFrong: Thanks. I was about to put it in pastebin, but it turns out it was a silly mistake, looking further. I wrote (def c chan) instead of (def c (chan))
23:13HamledCould someone explain why I get a "static field not found" exception when I do (map some.java.Class/staticFunc coll) but (map #(some.java.Class/staticFunc %) coll) works?
23:14justin_smithHamled: methods are not first class
23:15justin_smithHamled: Clojure could have decided to fake it, but instead it reflects the jvm's implementation
23:16Hamledah, seems understandable. Is there some kind of java construct that would work in that scenario, or is the "static field not found" exception just the result of the implementation of map
23:16Hamledlike, the exeption seems to imply to me that something perhaps other than a static method would be found if I tried to use that instead? I have no idea what that thing would be, though
23:17justin_smithHamled: I think a java object that was callable / invokable might work as the first arg to map? not certain of that though
23:17Hamledah
23:17Hamleda functor or something
23:17justin_smithmethods are only usable within forms where they can be resolved to their object
23:18justin_smithnot just a functor, an fn is an object that is callable / invocable for example
23:18Hamledoh
23:18HamledI suppose that makes sense, where else would you put it
23:19justin_smithright, to refer to a thing in java, you need its object - technically we could have done somthing funky with static methods and their class
23:19HamledI don't understand what you mean by "where they can be resolved to their object" -- wouldn't that not apply for a static method?
23:19Hamledoh okay
23:19justin_smithright, that's what I was getting at with "technically..."
23:19Hamledso the choice was not to special case static methods
23:19justin_smiththat's my impression, yes
23:19Hamledcool, thanks :)
23:20justin_smithin general there is a priority in clojure for keeping designs simple
23:20michaniskinhow would one debug why it takes a really long time to AOT compile certain namespaces?
23:20justin_smithmichaniskin: are you creating something stateful like a server thread at the top level? that's a common issue
23:21justin_smithmichaniskin: also, jstack will tell you exactly what each of your threads is doing, and you could run it during compilation
23:21michaniskinjustin_smith: i'm pretty sure i'm not
23:21justin_smithOK
23:21michaniskinaha, that sounds like what i need, thanks!
23:21justin_smithtry jstack and/or jvisualvm, yourkit, any of those can tell you where CPU is being burnt / what a thread is waiting on, etc.
23:22michaniskinyeah my cpu is not being utilized at all during the long wait
23:22michaniskinit seems like a TCP timeout or something crazy
23:23justin_smithmichaniskin: creating a URL object? those are resolved when created (which is weird and leads to weird bugs)
23:23michaniskinjustin_smith: whoa, i did not know that, but it makes sense
23:23michaniskinwell sort of makes sense, maybe
23:23justin_smithit actually makes very little sense that just creating a java.net.URL would do a host lookup, but it does :)
23:25michaniskinyeah seems like something that could also be exploited somehow
23:38andyfmichaniskin: If the wait is about 60 seconds, it could be a side effect of creating a future, or a call to pmap or clojure.java.shell/sh. See http://clojuredocs.org/clojure.core/future
23:42michaniskini think it's repl related, this namespace takes a really long time to compile, and it's like 10 lines of code: https://gist.github.com/df72b821f4347ae9aab1
23:43justin_smithmichaniskin: yeah, if that's it, I don't see why that would take so long to load, unless reply was doing something weird
23:43justin_smithnothing stateful is being created at the top level, clearly
23:45justin_smithwoah, reply monkeypatches clojure.core
23:45justin_smithlol
23:45justin_smithhttps://github.com/trptcolin/reply/blob/master/src/clj/reply/hacks/printing.clj#L39
23:53andyfI think reply might depend upon something that creates a future at the top level, IIRC. We saw something similar with this with Leiningen, which depends on reply.
23:53andyfLet me see if I can find the issue
23:56justin_smithin that case you would want to call shutdown agents when compiling? that's terrible though