2015-08-01
| 00:40 | slester | Is there an idiomatic way to search a vector of maps for a condition and return the matching indices? |
| 00:40 | slester | [{:thing true} {:thing false} {:thing false}], looking for {:thing false}, I want to return [1 2] |
| 00:40 | justin_smith | slester: it's easier to return the matching items, but with the help of map and range it's pretty easy |
| 00:41 | slester | yeah the matching items I have |
| 00:41 | slester | it's the indices that are tripping me up |
| 00:41 | slester | also I really appreciate you always answering justin_smith ! |
| 00:42 | justin_smith | ,(keep (fn [i m] (if (false? (:thing map)) i)) [{:thing true} {:thing false} {:thing false}]) |
| 00:42 | clojurebot | #<ArityException clojure.lang.ArityException: Wrong number of args (1) passed to: sandbox/eval25/fn--26> |
| 00:42 | justin_smith | err |
| 00:42 | justin_smith | ,(keep (fn [i m] (if (false? (:thing m)) i)) range [{:thing true} {:thing false} {:thing false}]) |
| 00:42 | clojurebot | #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:42 | justin_smith | ,(keep identity (map (fn [i m] (if (false? (:thing m)) i)) range [{:thing true} {:thing false} {:thing false}])) |
| 00:42 | clojurebot | #<IllegalArgumentException java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.core$range> |
| 00:43 | justin_smith | ,(keep identity (map (fn [i m] (if (false? (:thing m)) i)) (range) [{:thing true} {:thing false} {:thing false}])) ; I must be tired |
| 00:43 | clojurebot | (1 2) |
| 00:43 | justin_smith | or... |
| 00:43 | justin_smith | ,(mapcat (fn [i m] (if (false? (:thing m)) [i])) (range) [{:thing true} {:thing false} {:thing false}]) |
| 00:43 | clojurebot | (1 2) |
| 00:44 | slester | justin_smith, mapcat, nice, I've never used or seen that before. Very useful |
| 00:50 | justin_smith | slester: 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:31 | TEttinger | woah, I hadn't seen that either justin_smith. |
| 01:31 | TEttinger | nice |
| 01:31 | TEttinger | (inc mapcat) |
| 01:31 | lazybot | ⇒ 1 |
| 01:31 | TEttinger | (inc justin_smith) |
| 01:31 | lazybot | ⇒ 282 |
| 01:31 | TEttinger | wowza |
| 01:31 | TEttinger | (identity amalloy_) |
| 01:31 | lazybot | amalloy_ has karma 2. |
| 01:31 | TEttinger | (identity amalloy) |
| 01:31 | lazybot | amalloy has karma 288. |
| 01:32 | TEttinger | oh boy, neck and neck |
| 02:07 | J_Arcane | Anyone ever try doing the Little Lisper in Clojure? |
| 03:31 | wasamasa | s/lisper/schemer/ |
| 04:11 | J_Arcane | Heh. True. |
| 07:06 | Olajyd | What function can I use to check if a given number exist in a vector of numbers? |
| 07:08 | oddcully | ,(some #{5} [1 2 5 4]) |
| 07:08 | clojurebot | 5 |
| 07:10 | Olajyd | Thanks Oddcully |
| 07:48 | Olajyd | How do i check fro the length of a number of type double : (count (str 10.0000))? |
| 07:49 | Olajyd | Check for length of type double: (count (str 10.0000)) |
| 07:53 | oddcully | ,(count (str (- 0.3 0.2))) |
| 07:53 | clojurebot | 19 |
| 08:03 | kwladyka | is 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:04 | justin_smith | kwladyka: you could make :safe-squares a metadata |
| 08:04 | justin_smith | that doesn't effect the hashcode |
| 08:04 | kwladyka | justin_smith, thx i will read about that |
| 08:05 | kwladyka | justin_smith, how good you are always here :) |
| 08:05 | justin_smith | ,(def a (with-meta {:notation [:a]} {:safe-squares [1 2]}) |
| 08:05 | clojurebot | #<RuntimeException java.lang.RuntimeException: EOF while reading> |
| 08:05 | justin_smith | ,(def a (with-meta {:notation [:a]} {:safe-squares [1 2]})) |
| 08:05 | clojurebot | #'sandbox/a |
| 08:05 | justin_smith | ,a |
| 08:05 | clojurebot | {:notation [:a]} |
| 08:06 | justin_smith | (def b (with-meta {:notation [:a]} {:safe-squares [3 4]})) |
| 08:06 | justin_smith | ,(def b (with-meta {:notation [:a]} {:safe-squares [3 4]})) |
| 08:06 | clojurebot | #'sandbox/b |
| 08:06 | justin_smith | ,(= a b) |
| 08:06 | clojurebot | true |
| 08:06 | justin_smith | ,(map meta [a b]) |
| 08:06 | clojurebot | ({:safe-squares [1 2]} {:safe-squares [3 4]}) |
| 08:06 | justin_smith | kwladyka: that should be enough ^ |
| 08:07 | justin_smith | the metadata is always a hash-map |
| 08:07 | kwladyka | justin_smith, thx |
| 08:07 | justin_smith | kwladyka: the tricky part though is operations like conj or assoc don't preserve metadata, you need to pass it along explicitly |
| 08:07 | justin_smith | ,(meta (assoc a :b 0)) |
| 08:07 | clojurebot | {:safe-squares [1 2]} |
| 08:08 | justin_smith | oh wait |
| 08:08 | justin_smith | haha |
| 08:08 | justin_smith | so it does propagate, cool... |
| 08:09 | kwladyka | good news, i _think_ i found a bug in my algorithm, it is heuristic bug, but we will see |
| 08:09 | kwladyka | justin_smith, How long do you work with Clojure? |
| 08:12 | Olajyd | Given 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:16 | Olajyd | Given 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:17 | pleax | Olajyd: generally you can't do this with filter |
| 08:18 | pleax | Olajyd: but if you know which index to remove you can try to concat two subvec's |
| 08:18 | Olajyd | pleax gotcha |
| 08:21 | Olajyd | pleax: what if the index is known?.. Can i implement a filter function with the subvec or how do I go about it |
| 08:25 | pleax | Olajyd: simpliest way it something like (concat (subvec v 0 1) (subvec v 2)) |
| 08:25 | expez | While reading the source for tools.analyzer.jvm I saw (binding [*ns* *ns*] ...) why isn't that a no-op? |
| 08:26 | Olajyd | @pleax : Thanks |
| 08:26 | expez | Is it there to reset and (binding ..) above it on the stack? |
| 08:26 | expez | s/and/any/ |
| 09:37 | gfredericks | expez: if I understand you correctly, set! does that |
| 10:28 | dnolen | gfredericks: do you have link where I can try your build? |
| 10:31 | gfredericks | dnolen: https://github.com/gfredericks/exact/commit/d0865ee25a0d9879eb256e4afa6f2d5431a2ec66 |
| 10:31 | gfredericks | it's on a branch there called fork-goog-integer, if that's easier |
| 10:32 | gfredericks | (that link was in the original tweet, I wasn't expecting you to diagnose something pureely based off of "Assert failed") |
| 10:35 | dnolen | gfredericks: I just tried transit-cljs, seems to work fine, will take a look at your thing now |
| 10:40 | gfredericks | cool, thanks |
| 10:56 | dnolen | gfredericks: ah, I see the problem - there is a bug with the feature the .js lib has to be in a JAR |
| 10:56 | dnolen | which is why it worked w/ transit-cljs, but not your example |
| 10:57 | gfredericks | I thought of that distinction but didn't seem plausible enough to try |
| 10:57 | gfredericks | I can work with that though, thanks! |
| 10:57 | gfredericks | (inc dnolen) |
| 10:57 | lazybot | ⇒ 24 |
| 10:58 | dnolen | gfredericks: http://dev.clojure.org/jira/browse/CLJS-1387 |
| 11:00 | gfredericks | cool |
| 11:10 | tmtwd | is -> and --> like function composition in haskell? |
| 11:10 | gfredericks | somewhat |
| 11:11 | tmtwd | just somewhat? |
| 11:11 | tmtwd | they seem very similar |
| 11:11 | scriptor | comp is like function composition in haskell |
| 11:11 | tmtwd | Now that I think about it, I thik I brought it up at a clojure meetup, but was informed that its not |
| 11:12 | scriptor | -> and --> go further and expect the argument to be feedable at a specific point |
| 11:12 | tmtwd | what does that mean? |
| 11:13 | gfredericks | they're macros so they work with expressions instead of functions |
| 11:17 | tmtwd | oh |
| 11:17 | tmtwd | but it is a similar idea at least? |
| 11:17 | gfredericks | similar use cases |
| 11:17 | gfredericks | ,(macroexpand-1 '(-> x (foo 1) (bar 2 3 4) (baz))) |
| 11:17 | clojurebot | (baz (bar (foo x 1) 2 3 4)) |
| 11:17 | tmtwd | I can pretend they are like function composition, knowing that they are not? :) |
| 11:17 | gfredericks | ^ macroexpand-1 is good for seeing what it does |
| 11:18 | tmtwd | ah |
| 11:18 | tmtwd | good tip |
| 11:18 | gfredericks | compare to ->>: |
| 11:18 | gfredericks | ,(macroexpand-1 '(->> x (foo 1) (bar 2 3 4) (baz))) |
| 11:18 | clojurebot | (baz (bar 2 3 4 (foo 1 x))) |
| 11:32 | dnolen | tmtwd: I would avoid pretending, nasty surprises lurk |
| 11:33 | gfredericks | dnolen: throwing it in a jar works perfectly, thanks again! |
| 11:33 | dnolen | gfredericks: great! |
| 11:50 | dnolen | gfredericks: issue fixed in master |
| 12:27 | justin_smith | tmtwd: I guess we could say they are about form convolution, rather than function composition |
| 12:28 | justin_smith | ,(-> (java.util.HashMap.) (.put :a 0) (.put :b 1)) ; contains things that are not functions |
| 12:28 | clojurebot | #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:28 | justin_smith | err... |
| 12:28 | justin_smith | haha, put does not return the map |
| 12:29 | justin_smith | ,(let [m (java.util.HashMap.)] (-> m (.put :a 0) (.put :b 1)) m) ; contains things that are not functions |
| 12:29 | clojurebot | #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:29 | justin_smith | ,(let [m (java.util.HashMap.)] (-> m (.put :a 0)) m) |
| 12:29 | clojurebot | {:a 0} |
| 12:33 | oddcully | ,(doto (java.util.HashMap.) (.put :a 0) (.put :b 1)) |
| 12:33 | clojurebot | {:b 1, :a 0} |
| 12:46 | justin_smith | oddcully: but that doesn't compose forms of course |
| 12:46 | justin_smith | well, actually |
| 12:46 | justin_smith | ,(macroexpand-1 '(doto a b c)) |
| 12:46 | clojurebot | (clojure.core/let [G__27 a] (b G__27) (c G__27) G__27) |
| 12:47 | oddcully | i haven't payed attention to the discussion above. i just saw the last bit about "put not returning" |
| 12:47 | oddcully | just ignore me ;) |
| 13:16 | arav93 | How do we create a node type of thingy in clojure.zip |
| 17:35 | tmtwd | does cljs need an 'init' or main method to run? |
| 17:35 | tmtwd | I don't think javascript needs one but maybe cljs does |
| 17:47 | justin_smith | tmtwd: 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:47 | tmtwd | yes |
| 17:47 | tmtwd | i see |
| 17:47 | justin_smith | so I have a test.html that instead of ivoking the main, loads my test namespaces and invokes run-all-tests |
| 17:47 | tmtwd | it works like javascript mostly |
| 17:47 | justin_smith | right, it outputs javascript :) |
| 20:17 | justmytwospence | I'm having some trouble connecting an org-babel buffer to CIDER |
| 20:18 | justmytwospence | CIDER is running, but when I try to execute source code blocks, it says "not connected" |
| 20:19 | justmytwospence | most of the documentation for using org-babel with clojure is outdated |
| 20:27 | arrdem | justmytwospence: do you have cider-mode on in that buffer? |
| 20:27 | arrdem | justmytwospence: that's how CIDER chooses which connection (if any) to eval to |
| 20:28 | arrdem | justmytwospence: if you get this working please please write it up :P |
| 20:28 | arrdem | the docs as you say are quite stale |
| 20:47 | justmytwospence | arrdem: i executed cider-jack-in from the org buffer, so it should be connected, yes? |
| 20:50 | justin_smith | justmytwospence: no it does not work that way |
| 20:51 | justmytwospence | justin_smith: how should I do it? |
| 20:51 | justin_smith | justmytwospence: 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:53 | justmytwospence | justin_smith: if i explicitly enable cider mode, it overrides the org-babel C-C C-c keybinding |
| 20:54 | justin_smith | justmytwospence: I don't even know if using org-babel with new cider versions is possible, sorry. Wish I could offer more help. |
| 22:12 | arrdem | justmytwospence: not the org buffer itself, the bable output buffer |
| 23:38 | timvisher | is there a safe way to parse a string to an int, just returning nil if it couldn't be done? |
| 23:39 | timvisher | ,(try (Integer/parseInt "1") (catch Exception e)) |
| 23:39 | clojurebot | timvisher: Pardon? |
| 23:39 | timvisher | ,(try (Integer/parseInt "1") (catch Exception e nil)) |
| 23:39 | clojurebot | timvisher: Excuse me? |
| 23:39 | timvisher | hrm... |
| 23:39 | justin_smith | timvisher: clojurebot doesn't do try/catch |
| 23:39 | timvisher | oh lol |
| 23:40 | timvisher | anywho, that's how i would write it, but i'm wondering if that already exists in the stdlib somewhere |
| 23:40 | timvisher | maybe in numeric tower somewhere? |
| 23:43 | timvisher | ah looks like it's in useful https://github.com/amalloy/useful/blob/1c436605f31fedca916f0e3c172b0b0c06f621d0/src/flatland/useful/datatypes.clj#L10-L15 |
| 23:44 | timvisher | hrm, nope. that still doesn't catch exceptions |