workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
clojurians | clojure | still seeing `reduce` version out-perform for small inputs by ~10% | 2017-11-29T15:06:26.000331 | Owen |
clojurians | clojure | <https://github.com/clojure/clojure/blob/clojure-1.9.0-alpha14/src/clj/clojure/core.clj#L1501-L1513> | 2017-11-29T15:08:19.000331 | Berry |
clojurians | clojure | I'm disappointed the apply version doesn't end up using transients | 2017-11-29T15:08:26.000269 | Berry |
clojurians | clojure | transients do actually give the reduce version a significant edge
```
(criterium.core/quick-bench (apply dissoc m s2))
Evaluation count : 6 in 6 samples of 1 calls.
Execution time mean : 336.386302 ms
Execution time std-deviation : 19.057339 ms
Execution time lower quantile : 319.084193 ms ( 2.5%)
Execution time upper quantile : 360.243222 ms (97.5%)
Overhead used : 1.529080 ns
=> nil
(criterium.core/quick-bench (reduce dissoc m s2))
Evaluation count : 6 in 6 samples of 1 calls.
Execution time mean : 330.780186 ms
Execution time std-deviation : 30.145095 ms
Execution time lower quantile : 291.699187 ms ( 2.5%)
Execution time upper quantile : 360.677617 ms (97.5%)
Overhead used : 1.529080 ns
=> nil
(criterium.core/quick-bench (persistent! (reduce dissoc! (transient m) s2)))
Evaluation count : 6 in 6 samples of 1 calls.
Execution time mean : 226.415054 ms
Execution time std-deviation : 7.032915 ms
Execution time lower quantile : 217.464830 ms ( 2.5%)
Execution time upper quantile : 233.430482 ms (97.5%)
Overhead used : 1.529080 ns
``` | 2017-11-29T15:09:25.000151 | Aldo |
clojurians | clojure | (for large inputs, for small they incur a small cost) | 2017-11-29T15:09:46.000473 | Aldo |
clojurians | clojure | <@Aldo>: you beat me to it, was just about to post transient code | 2017-11-29T15:14:42.000748 | Berry |
clojurians | clojure | ```
(def lst (for [x (range 1000000)] [x x]))
(defn massoc! [o [k v]]
(assoc! o k v))
(cc/quick-bench (into {} lst))
(comment
Execution time mean : 591.524037 ms
Execution time std-deviation : 68.112686 ms
Execution time lower quantile : 555.200521 ms ( 2.5%)
Execution time upper quantile : 709.664574 ms (97.5%)
Overhead used : 2.943666 ns
Found 1 outliers in 6 samples (16.6667 %)
low-severe 1 (16.6667 %)
Variance from outliers : 31.1510 % Variance is moderately inflated by outliers)
(cc/quick-bench (persistent! (reduce massoc! (transient {}) lst)))
(comment
Execution time mean : 515.178533 ms
Execution time std-deviation : 69.452690 ms
Execution time lower quantile : 482.675140 ms ( 2.5%)
Execution time upper quantile : 635.692003 ms (97.5%)
Overhead used : 2.943666 ns
Found 2 outliers in 6 samples (33.3333 %)
low-severe 1 (16.6667 %)
low-mild 1 (16.6667 %)
Variance from outliers : 31.7413 % Variance is moderately inflated by outliers)
```
Why doesn't clojure core use transients by default ? | 2017-11-29T15:22:24.000714 | Berry |
clojurians | clojure | <@Berry>: `into` *does* use transients | 2017-11-29T16:17:47.000065 | Tai |
clojurians | clojure | see here (relevant part of `into` source from `core.clj`):
```
(defn into
([to from]
(if (instance? clojure.lang.IEditableCollection to)
(with-meta (persistent! (reduce conj! (transient to) from)) (meta to))
(reduce conj to from))))
``` | 2017-11-29T16:19:44.000088 | Tai |
clojurians | clojure | I have a long list of validation checks, and steps that happen interleaved among them. The validation checks can throw errors:
right now I have:
```
(let [_ (check)
a (f)
_ (check2)
b (g)
...]
z)
```
basically, those validations/throwing errors are a way to short circuit the logic
the main alternative I see is a series of `if` each with a nested `let`
is there a cleaner way of achieving this sort of `Either` monad pattern? | 2017-11-29T16:25:26.000023 | Lori |
clojurians | clojure | <@Tai>: good call, thanks for the correction | 2017-11-29T16:39:16.000128 | Berry |
clojurians | clojure | <@Lori> `some->` ? | 2017-11-29T17:10:21.000885 | Marx |
clojurians | clojure | yeah, I usually use some-> or some->> for that kind of thing | 2017-11-29T17:11:25.000592 | Margaret |
clojurians | clojure | but reduce, then returning a reduced as appropriate can work too | 2017-11-29T17:11:51.000478 | Margaret |
clojurians | clojure | `(reduce (fn [acc v] (if (borked? acc) (reduced acc) (frob acc v)) init coll)` | 2017-11-29T17:12:30.000323 | Margaret |
clojurians | clojure | The nice thing about `reduce`/`reduced` is you can return something other than `nil` if any of the steps fail. | 2017-11-29T17:12:47.000559 | Marx |
clojurians | clojure | indeed | 2017-11-29T17:12:53.000311 | Margaret |
clojurians | clojure | re `some->`, kind of, but I need to report details of where it failed
re `reduced`, interesting, I hadn't considered that, I kind of like that | 2017-11-29T17:12:55.000850 | Lori |
clojurians | clojure | your coll is likely to be a vector of checks to run in that case | 2017-11-29T17:13:29.000404 | Margaret |
clojurians | clojure | I'm not really moving across a collection though... | 2017-11-29T17:13:29.000421 | Lori |
clojurians | clojure | oh | 2017-11-29T17:13:34.000169 | Lori |
clojurians | clojure | It’s that weird fp stuff, instead of reducing a function over a collection of args, you reduce an arg over a collection of fns. :wink: | 2017-11-29T17:14:39.000325 | Marx |
clojurians | clojure | so `(reduce (fn [context check] (let [checked (check context)] (if (OK? checked) checked (reduced checked)) {} [check1 check2])` sort of like this | 2017-11-29T17:15:09.000358 | Margaret |
clojurians | clojure | and then the hash map can hold a, b, etc. under keys | 2017-11-29T17:15:42.000527 | Margaret |
clojurians | clojure | and then the collection I'm accumulating would be my otherwise `let` bound vars. ya, the `context` | 2017-11-29T17:15:57.000068 | Lori |
clojurians | clojure | though at this point loop/recur might be easier to read? | 2017-11-29T17:16:13.000459 | Margaret |
clojurians | clojure | your call | 2017-11-29T17:16:21.000362 | Margaret |
clojurians | clojure | <@Margaret> that's a genius pattern, I'll see if it works for this, thanks | 2017-11-29T17:16:44.000029 | Lori |
clojurians | clojure | :thumbsup: | 2017-11-29T17:16:53.000401 | Margaret |
clojurians | clojure | it’s something I have used to success in my own code | 2017-11-29T17:17:02.000301 | Margaret |
clojurians | clojure | you might also want to look at the new halt-when transducer in 1.9 (although it’s a little tricky to use well) | 2017-11-29T17:59:04.000001 | Sonny |
clojurians | clojure | Has anyone used a clojure wrapper around git's cli? There are some that wrap JGit, but as far as I can tell JGit does not yet support 'clone --mirror ...' and I need that functionality. | 2017-11-29T18:37:33.000552 | Bibi |
clojurians | clojure | <@Bibi> I’d generally look at doing interop before opting for a wrapper anyway - if the API is a total pain I then check for a wrapper, but often just using interop is fine | 2017-11-29T18:39:34.000056 | Margaret |
clojurians | clojure | agreed, in that I don't need any more functionality other than 'clone --mirror' and then 'push --mirror' | 2017-11-29T18:40:07.000532 | Bibi |
clojurians | clojure | maybe even running the shell command... | 2017-11-29T18:40:28.000211 | Bibi |
clojurians | clojure | shell interop :slightly_smiling_face: | 2017-11-29T18:40:35.000228 | Bibi |
clojurians | clojure | that’s straightforward to use, if it’s good enough | 2017-11-29T18:40:47.000155 | Margaret |
clojurians | clojure | plus authentication | 2017-11-29T18:40:50.000024 | Bibi |
clojurians | clojure | yeah, I'll try that out. Thanks! And by the way, you're absolutely one of the busiest sources of help here... really appreciated. | 2017-11-29T18:41:25.000078 | Bibi |
clojurians | clojure | oh, thanks | 2017-11-29T18:41:56.000412 | Margaret |
clojurians | clojure | By 'busiest' I mean as soon as a see someone with a question, I see 'noisesmith typing...' :slightly_smiling_face: | 2017-11-29T18:42:39.000070 | Bibi |
clojurians | clojure | I would be living on the street without <@Margaret> | 2017-11-29T18:44:13.000214 | Lily |
clojurians | clojure | haha | 2017-11-29T18:44:25.000039 | Margaret |
clojurians | clojure | agreed, <@Margaret> is one of the most helpful people here; we should start tipping him in micro bitcoins or something :slightly_smiling_face: | 2017-11-29T19:03:23.000184 | Berry |
clojurians | clojure | Does anybody have any Emacs configs to expand upon this? <http://fgiasson.com/blog/index.php/2016/06/14/my-optimal-gnu-emacs-settings-for-developing-clojure-revised/> I adopted this config when I started just under a year ago and I never thought about it since | 2017-11-29T21:26:58.000202 | Giovanni |
clojurians | clojure | I’ve switched to the `zenburn` theme because I find it easier on my eyes than `monokai`. I configured `erc-mode` because the leiningen developers hang out on IRC, and I have a pull request pending there. I’ve recently adopted `eshell` and added some config tweaks I needed, including a custom prompt for `virtualenvwrapper`. Up until very recently I used exclusively melpa-stable, but then I released a (silly) elisp package called `adafruit-wisdom` to melpa… As a result, I needed to figure out how to pin packages to a specific repository, that’s the stuff at the very top of my `init.el`. Take a look, maybe some of this will appeal to you too. <https://github.com/gonewest818/.emacs.d> | 2017-11-29T23:41:11.000096 | Kyung |
clojurians | clojure | <@Giovanni> you may take a look at my emacs config that I’ve been using for 5 years: <https://github.com/igrishaev/dotfiles/blob/master/.emacs> | 2017-11-30T01:30:07.000071 | Verna |
clojurians | clojure | How come `coll-reduce` isn't implemented for `Iterator`? | 2017-11-30T02:16:54.000187 | Randee |
clojurians | clojure | 1. I'm not using datomic.
2. I need to inspect a large eav store (about 10,000 items).
3. Anyone knows of a good tool for analyzing this? | 2017-11-30T02:59:41.000085 | Berry |
clojurians | clojure | 10000 items isn’t exactly large | 2017-11-30T03:23:13.000090 | Cecilia |
clojurians | clojure | I think you can just load that into memory and use Datascript | 2017-11-30T03:23:58.000125 | Cecilia |
clojurians | clojure | no no, I meant I'm currently dumping it via println | 2017-11-30T04:42:22.000382 | Berry |
clojurians | clojure | and manually inspecting it by hand when something goes wrong | 2017-11-30T04:42:29.000209 | Berry |
clojurians | clojure | (s/def ::delay (s/and (s/or :val pos? :val zero?) int?)) | 2017-11-30T06:05:06.000002 | Anneliese |
clojurians | clojure | (s/valid? ::delay 0) | 2017-11-30T06:05:07.000064 | Anneliese |
clojurians | clojure | gives false | 2017-11-30T06:05:14.000025 | Anneliese |
clojurians | clojure | if I restructure the ::delay to (s/def ::delay (s/and int? (s/or :val pos? :val zero?))) | 2017-11-30T06:05:58.000323 | Anneliese |
clojurians | clojure | it then works | 2017-11-30T06:06:02.000451 | Anneliese |
clojurians | clojure | can anyone explain why | 2017-11-30T06:06:13.000165 | Anneliese |
clojurians | clojure | (s/def ::delay (s/and (s/or :val pos? :val zero?) int?))
(s/valid? ::delay 0) => false
(s/def ::delay (s/and int? (s/or :val pos? :val zero?)))
(s/valid? ::delay 0) => true | 2017-11-30T06:15:09.000264 | Anneliese |
clojurians | clojure | you can use `s/explain` in place of `s/valid?` to get more information | 2017-11-30T06:15:42.000049 | James |
clojurians | clojure | I tried it here and it seems like the first option passes `[:val 0]` to the `int?` pred | 2017-11-30T06:16:21.000509 | James |
clojurians | clojure | so this is probably what's causing it to fail | 2017-11-30T06:17:05.000061 | James |
clojurians | clojure | is it normal behavior? | 2017-11-30T06:17:23.000255 | Anneliese |
clojurians | clojure | i think it shouldn't | 2017-11-30T06:17:36.000200 | Anneliese |
clojurians | clojure | Seems that's the case as `(spec/def ::delay (spec/and (spec/or :val pos? :val zero?) #(int? (second %))))` works | 2017-11-30T06:18:25.000109 | James |
clojurians | clojure | <https://clojuredocs.org/clojure.spec/or>
"Returns a destructuring spec that returns a map entry containing the
key of the first matching pred and the corresponding value." | 2017-11-30T06:18:28.000220 | Rogelio |
clojurians | clojure | and that I don't know enough to say | 2017-11-30T06:19:00.000071 | James |
clojurians | clojure | I thought that the above would only be true when conforming, didn't realize it would have this kind of implication | 2017-11-30T06:20:03.000062 | James |
clojurians | clojure | btw <@Anneliese> you can use `pos-int?` as well | 2017-11-30T06:20:32.000432 | James |
clojurians | clojure | I think it makes sense. This way, you can check only specific keys in the following specs. | 2017-11-30T06:20:58.000082 | Rogelio |
clojurians | clojure | or <https://clojuredocs.org/clojure.core/nat-int_q> | 2017-11-30T06:21:21.000251 | James |
clojurians | clojure | <@Rogelio> that is true | 2017-11-30T06:21:52.000185 | James |
clojurians | clojure | I have something like this (reduce + (map #(* (first %) (last %)) …) that runs at 1500msecs. Then I tried it in a loop and it drops to 20msecs. Why does Rich hickey hate me so ? | 2017-11-30T09:46:27.000393 | Sherrie |
clojurians | clojure | How did you do it in a loop? | 2017-11-30T09:50:56.000022 | Rogelio |
clojurians | clojure | (loop [acc 0 item items] (if (seq item) (recur (+ acc (….))) acc) | 2017-11-30T09:52:24.000122 | Sherrie |
clojurians | clojure | something like that | 2017-11-30T09:52:26.000110 | Sherrie |
clojurians | clojure | Still not clear. :slightly_smiling_face: It depends on what `items` is and how you recur on `item`. | 2017-11-30T09:53:52.000033 | Rogelio |
clojurians | clojure | In CLJS and `items` being a vector, `reduce` works about 8% faster than `loop`:
```(def items (mapv #(vector % %) (range 10000)))```
```
(simple-benchmark [] (reduce + (map #(* (first %) (last %)) items)) 1000)
[], (reduce + (map (fn* [p1__115369#] (* (first p1__115369#) (last p1__115369#))) items)), 1000 runs, 4812 msecs
```
```
(simple-benchmark [] (loop [acc 0, items items] (if (seq items) (recur (let [i (first items)] (+ acc (* (first i) (last i)))) (rest items)) acc)) 1000)
[], (loop [acc 0 items items] (if (seq items) (recur (let [i (first items)] (+ acc (* (first i) (last i)))) (rest items)) acc)), 1000 runs, 5219 msecs
``` | 2017-11-30T10:10:42.000523 | Rogelio |
clojurians | clojure | Just a suggestion. Is it because map creates a new list, before reducing on it? I wonder how this would perform:
(reduce #(+ (* (first %2) (last %2)) %1) 0 ....)
Skipping the creation of the intermediate list. | 2017-11-30T10:11:42.000667 | Ha |
clojurians | clojure | There's no an intermediate list. `map` is lazy. | 2017-11-30T10:12:26.000535 | Rogelio |
clojurians | clojure | I wonder what time you get with `first` and `peek` (instead of last) in the `map` version | 2017-11-30T10:20:13.000747 | Lorenza |
clojurians | clojure | <@Rogelio> Use destructing instead of first/last. Last isn't all that fast and will create another intermediate sequence actually. | 2017-11-30T10:24:26.000284 | Randee |
clojurians | clojure | <@Randee> I know, I was deliberately repeating what laujensen provided. | 2017-11-30T10:25:09.000419 | Rogelio |
clojurians | clojure | Oh I see! :slightly_smiling_face: | 2017-11-30T10:25:21.000139 | Randee |
clojurians | clojure | ```(simple-benchmark [] (reduce + (map #(* (first %) (peek %)) items)) 1000)
[], (reduce + (map (fn* [p1__118806#] (* (first p1__118806#) (peek p1__118806#))) items)), 1000 runs, 2304 msecs``` | 2017-11-30T10:29:09.000017 | Rogelio |
clojurians | clojure | By the way, `first` with `peek` is faster than destructuring by about 15%. | 2017-11-30T10:32:07.000348 | Rogelio |
clojurians | clojure | you can't destructure `last` | 2017-11-30T10:32:59.000518 | Kareen |
clojurians | clojure | items are a two element vector so you can in this instance but certainly not in the general sense of `last` | 2017-11-30T10:34:37.000007 | Willow |
clojurians | clojure | <@Sherrie> also make sure your first reduce isn't actually realizing the lazy seq vs your loop using the already realized one | 2017-11-30T10:35:45.000237 | Kareen |
clojurians | clojure | there's just way too much you haven't said about this to make a guess, but there's absolutaly no way that a 1:1 translation from reduce to loop results in 2 factors of magnitude perf increase | 2017-11-30T10:36:36.000161 | Kareen |
clojurians | clojure | in fact, often reduce is faster than manual looping over a seq view | 2017-11-30T10:36:45.000682 | Kareen |
clojurians | clojure | Thanks for the input guys, I'll fiddle a bit | 2017-11-30T11:13:47.000508 | Sherrie |
clojurians | clojure | hello everyone, im coding a scheduler which receives a function as a parameter, if the function execution raises an exception, id like to log the function name
is there a standart way of getting a function name in clojure? | 2017-11-30T11:17:06.000303 | Amado |
clojurians | clojure | no | 2017-11-30T11:17:55.000542 | Kareen |
clojurians | clojure | (-> func meta :name) ? | 2017-11-30T11:18:15.000361 | Sherrie |
clojurians | clojure | that works if you pass a `Var`, not if you pass a function as a value | 2017-11-30T11:19:21.000673 | Kareen |
clojurians | clojure | ```
;; get name of the created class for foo
((fn [f]
(-> f
.getClass
.getName)) clojure.string/replace) => clojure.string$replace
``` | 2017-11-30T11:23:51.000614 | Hedwig |
clojurians | clojure | It's a bit hacky. | 2017-11-30T11:23:58.000804 | Hedwig |
clojurians | clojure | And expensive I believe, because you do a reflection. | 2017-11-30T11:32:15.000165 | Hedwig |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.