#clojure logs

2015-08-01

00:40slesterIs there an idiomatic way to search a vector of maps for a condition and return the matching indices?
00:40slester[{:thing true} {:thing false} {:thing false}], looking for {:thing false}, I want to return [1 2]
00:40justin_smithslester: it's easier to return the matching items, but with the help of map and range it's pretty easy
00:41slesteryeah the matching items I have
00:41slesterit's the indices that are tripping me up
00:41slesteralso I really appreciate you always answering justin_smith !
00:42justin_smith,(keep (fn [i m] (if (false? (:thing map)) i)) [{:thing true} {:thing false} {:thing false}])
00:42clojurebot#<ArityException clojure.lang.ArityException: Wrong number of args (1) passed to: sandbox/eval25/fn--26>
00:42justin_smitherr
00:42justin_smith,(keep (fn [i m] (if (false? (:thing m)) i)) range [{:thing true} {:thing false} {:thing false}])
00:42clojurebot#error {\n :cause "Wrong number of args (3) passed to: core/keep"\n :via\n [{:type clojure.lang.ArityException\n :message "Wrong number of args (3) passed to: core/keep"\n :at [clojure.lang.AFn throwArity "AFn.java" 429]}]\n :trace\n [[clojure.lang.AFn throwArity "AFn.java" 429]\n [clojure.lang.AFn invoke "AFn.java" 40]\n [sandbox$eval51 invoke "NO_SOURCE_FILE" 0]\n [clojure.lang.Compiler e...
00:42justin_smith,(keep identity (map (fn [i m] (if (false? (:thing m)) i)) range [{:thing true} {:thing false} {:thing false}]))
00:42clojurebot#<IllegalArgumentException java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.core$range>
00:43justin_smith,(keep identity (map (fn [i m] (if (false? (:thing m)) i)) (range) [{:thing true} {:thing false} {:thing false}])) ; I must be tired
00:43clojurebot(1 2)
00:43justin_smithor...
00:43justin_smith,(mapcat (fn [i m] (if (false? (:thing m)) [i])) (range) [{:thing true} {:thing false} {:thing false}])
00:43clojurebot(1 2)
00:44slesterjustin_smith, mapcat, nice, I've never used or seen that before. Very useful
00:50justin_smithslester: at first I didn't realize mapcat wasn't just for putting more than one item into a coll per step - it can also be for putting less than one item into a coll
01:31TEttingerwoah, I hadn't seen that either justin_smith.
01:31TEttingernice
01:31TEttinger(inc mapcat)
01:31lazybot⇒ 1
01:31TEttinger(inc justin_smith)
01:31lazybot⇒ 282
01:31TEttingerwowza
01:31TEttinger(identity amalloy_)
01:31lazybotamalloy_ has karma 2.
01:31TEttinger(identity amalloy)
01:31lazybotamalloy has karma 288.
01:32TEttingeroh boy, neck and neck
02:07J_ArcaneAnyone ever try doing the Little Lisper in Clojure?
03:31wasamasas/lisper/schemer/
04:11J_ArcaneHeh. True.
07:06OlajydWhat function can I use to check if a given number exist in a vector of numbers?
07:08oddcully,(some #{5} [1 2 5 4])
07:08clojurebot5
07:10OlajydThanks Oddcully
07:48OlajydHow do i check fro the length of a number of type double : (count (str 10.0000))?
07:49OlajydCheck for length of type double: (count (str 10.0000))
07:53oddcully,(count (str (- 0.3 0.2)))
07:53clojurebot19
08:03kwladykais it possible to change hashcode in Clojure? I have Sets. And i am adding there maps {:notation [...] :safe-squares [...]}, but there is no reason to check :safe-squares, i only care about :notation, so i want change hashcode of this map to hashcode of :notation
08:04justin_smithkwladyka: you could make :safe-squares a metadata
08:04justin_smiththat doesn't effect the hashcode
08:04kwladykajustin_smith, thx i will read about that
08:05kwladykajustin_smith, how good you are always here :)
08:05justin_smith,(def a (with-meta {:notation [:a]} {:safe-squares [1 2]})
08:05clojurebot#<RuntimeException java.lang.RuntimeException: EOF while reading>
08:05justin_smith,(def a (with-meta {:notation [:a]} {:safe-squares [1 2]}))
08:05clojurebot#'sandbox/a
08:05justin_smith,a
08:05clojurebot{:notation [:a]}
08:06justin_smith(def b (with-meta {:notation [:a]} {:safe-squares [3 4]}))
08:06justin_smith,(def b (with-meta {:notation [:a]} {:safe-squares [3 4]}))
08:06clojurebot#'sandbox/b
08:06justin_smith,(= a b)
08:06clojurebottrue
08:06justin_smith,(map meta [a b])
08:06clojurebot({:safe-squares [1 2]} {:safe-squares [3 4]})
08:06justin_smithkwladyka: that should be enough ^
08:07justin_smiththe metadata is always a hash-map
08:07kwladykajustin_smith, thx
08:07justin_smithkwladyka: the tricky part though is operations like conj or assoc don't preserve metadata, you need to pass it along explicitly
08:07justin_smith,(meta (assoc a :b 0))
08:07clojurebot{:safe-squares [1 2]}
08:08justin_smithoh wait
08:08justin_smithhaha
08:08justin_smithso it does propagate, cool...
08:09kwladykagood news, i _think_ i found a bug in my algorithm, it is heuristic bug, but we will see
08:09kwladykajustin_smith, How long do you work with Clojure?
08:12OlajydGiven a vector of vectors [[a b] [b c] [c d]], I want to implement a filter function to remove the second index (i.e index 1).. How do I go about this?
08:16OlajydGiven a vector of vectors [[a b] [b c] [c d]], I want to implement a filter function to remove the vector in the second index (i.e index 1)..the filter will return a result like this [ [a b] [c d] ] How do I go about this?
08:17pleaxOlajyd: generally you can't do this with filter
08:18pleaxOlajyd: but if you know which index to remove you can try to concat two subvec's
08:18Olajydpleax gotcha
08:21Olajydpleax: what if the index is known?.. Can i implement a filter function with the subvec or how do I go about it
08:25pleaxOlajyd: simpliest way it something like (concat (subvec v 0 1) (subvec v 2))
08:25expezWhile reading the source for tools.analyzer.jvm I saw (binding [*ns* *ns*] ...) why isn't that a no-op?
08:26Olajyd@pleax : Thanks
08:26expezIs it there to reset and (binding ..) above it on the stack?
08:26expezs/and/any/
09:37gfredericksexpez: if I understand you correctly, set! does that
10:28dnolengfredericks: do you have link where I can try your build?
10:31gfredericksdnolen: https://github.com/gfredericks/exact/commit/d0865ee25a0d9879eb256e4afa6f2d5431a2ec66
10:31gfredericksit's on a branch there called fork-goog-integer, if that's easier
10:32gfredericks(that link was in the original tweet, I wasn't expecting you to diagnose something pureely based off of "Assert failed")
10:35dnolengfredericks: I just tried transit-cljs, seems to work fine, will take a look at your thing now
10:40gfrederickscool, thanks
10:56dnolengfredericks: ah, I see the problem - there is a bug with the feature the .js lib has to be in a JAR
10:56dnolenwhich is why it worked w/ transit-cljs, but not your example
10:57gfredericksI thought of that distinction but didn't seem plausible enough to try
10:57gfredericksI can work with that though, thanks!
10:57gfredericks(inc dnolen)
10:57lazybot⇒ 24
10:58dnolengfredericks: http://dev.clojure.org/jira/browse/CLJS-1387
11:00gfrederickscool
11:10tmtwdis -> and --> like function composition in haskell?
11:10gfrederickssomewhat
11:11tmtwdjust somewhat?
11:11tmtwdthey seem very similar
11:11scriptorcomp is like function composition in haskell
11:11tmtwdNow that I think about it, I thik I brought it up at a clojure meetup, but was informed that its not
11:12scriptor-> and --> go further and expect the argument to be feedable at a specific point
11:12tmtwdwhat does that mean?
11:13gfredericksthey're macros so they work with expressions instead of functions
11:17tmtwdoh
11:17tmtwdbut it is a similar idea at least?
11:17gfrederickssimilar use cases
11:17gfredericks,(macroexpand-1 '(-> x (foo 1) (bar 2 3 4) (baz)))
11:17clojurebot(baz (bar (foo x 1) 2 3 4))
11:17tmtwdI can pretend they are like function composition, knowing that they are not? :)
11:17gfredericks^ macroexpand-1 is good for seeing what it does
11:18tmtwdah
11:18tmtwdgood tip
11:18gfrederickscompare to ->>:
11:18gfredericks,(macroexpand-1 '(->> x (foo 1) (bar 2 3 4) (baz)))
11:18clojurebot(baz (bar 2 3 4 (foo 1 x)))
11:32dnolentmtwd: I would avoid pretending, nasty surprises lurk
11:33gfredericksdnolen: throwing it in a jar works perfectly, thanks again!
11:33dnolengfredericks: great!
11:50dnolengfredericks: issue fixed in master
12:27justin_smithtmtwd: I guess we could say they are about form convolution, rather than function composition
12:28justin_smith,(-> (java.util.HashMap.) (.put :a 0) (.put :b 1)) ; contains things that are not functions
12:28clojurebot#error {\n :cause nil\n :via\n [{:type java.lang.NullPointerException\n :message nil\n :at [clojure.lang.Reflector invokeInstanceMethod "Reflector.java" 26]}]\n :trace\n [[clojure.lang.Reflector invokeInstanceMethod "Reflector.java" 26]\n [sandbox$eval25 invoke "NO_SOURCE_FILE" 0]\n [clojure.lang.Compiler eval "Compiler.java" 6850]\n [clojure.lang.Compiler eval "Compiler.java" 6813]\n [clo...
12:28justin_smitherr...
12:28justin_smithhaha, put does not return the map
12:29justin_smith,(let [m (java.util.HashMap.)] (-> m (.put :a 0) (.put :b 1)) m) ; contains things that are not functions
12:29clojurebot#error {\n :cause nil\n :via\n [{:type java.lang.NullPointerException\n :message nil\n :at [clojure.lang.Reflector invokeInstanceMethod "Reflector.java" 26]}]\n :trace\n [[clojure.lang.Reflector invokeInstanceMethod "Reflector.java" 26]\n [sandbox$eval49 invoke "NO_SOURCE_FILE" 0]\n [clojure.lang.Compiler eval "Compiler.java" 6850]\n [clojure.lang.Compiler eval "Compiler.java" 6813]\n [clo...
12:29justin_smith,(let [m (java.util.HashMap.)] (-> m (.put :a 0)) m)
12:29clojurebot{:a 0}
12:33oddcully,(doto (java.util.HashMap.) (.put :a 0) (.put :b 1))
12:33clojurebot{:b 1, :a 0}
12:46justin_smithoddcully: but that doesn't compose forms of course
12:46justin_smithwell, actually
12:46justin_smith,(macroexpand-1 '(doto a b c))
12:46clojurebot(clojure.core/let [G__27 a] (b G__27) (c G__27) G__27)
12:47oddcullyi haven't payed attention to the discussion above. i just saw the last bit about "put not returning"
12:47oddcullyjust ignore me ;)
13:16arav93How do we create a node type of thingy in clojure.zip
17:35tmtwddoes cljs need an 'init' or main method to run?
17:35tmtwdI don't think javascript needs one but maybe cljs does
17:47justin_smithtmtwd: what I like to do is define a main method and then call it in a script tag - that way I can run tests without invoking my main method
17:47tmtwdyes
17:47tmtwdi see
17:47justin_smithso I have a test.html that instead of ivoking the main, loads my test namespaces and invokes run-all-tests
17:47tmtwdit works like javascript mostly
17:47justin_smithright, it outputs javascript :)
20:17justmytwospenceI'm having some trouble connecting an org-babel buffer to CIDER
20:18justmytwospenceCIDER is running, but when I try to execute source code blocks, it says "not connected"
20:19justmytwospencemost of the documentation for using org-babel with clojure is outdated
20:27arrdemjustmytwospence: do you have cider-mode on in that buffer?
20:27arrdemjustmytwospence: that's how CIDER chooses which connection (if any) to eval to
20:28arrdemjustmytwospence: if you get this working please please write it up :P
20:28arrdemthe docs as you say are quite stale
20:47justmytwospencearrdem: i executed cider-jack-in from the org buffer, so it should be connected, yes?
20:50justin_smithjustmytwospence: no it does not work that way
20:51justmytwospencejustin_smith: how should I do it?
20:51justin_smithjustmytwospence: I have no idea, but cider doesn't turn on cider mode in a buffer when you run cider-jack-in from that buffer
20:53justmytwospencejustin_smith: if i explicitly enable cider mode, it overrides the org-babel C-C C-c keybinding
20:54justin_smithjustmytwospence: I don't even know if using org-babel with new cider versions is possible, sorry. Wish I could offer more help.
22:12arrdemjustmytwospence: not the org buffer itself, the bable output buffer
23:38timvisheris there a safe way to parse a string to an int, just returning nil if it couldn't be done?
23:39timvisher,(try (Integer/parseInt "1") (catch Exception e))
23:39clojurebottimvisher: Pardon?
23:39timvisher,(try (Integer/parseInt "1") (catch Exception e nil))
23:39clojurebottimvisher: Excuse me?
23:39timvisherhrm...
23:39justin_smithtimvisher: clojurebot doesn't do try/catch
23:39timvisheroh lol
23:40timvisheranywho, that's how i would write it, but i'm wondering if that already exists in the stdlib somewhere
23:40timvishermaybe in numeric tower somewhere?
23:43timvisherah looks like it's in useful https://github.com/amalloy/useful/blob/1c436605f31fedca916f0e3c172b0b0c06f621d0/src/flatland/useful/datatypes.clj#L10-L15
23:44timvisherhrm, nope. that still doesn't catch exceptions