workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
clojurians | clojure | (s/transform [MAP-VALS MAP-VALS MAP-VALS (fn [h] ((comp not nil?) (re-find #"wow" (:title h))))] identity res) why not i got all titles with "wow" string and got all values ? | 2017-12-13T06:15:47.000328 | Mallory |
clojurians | clojure | i only want to filter those which has wow string | 2017-12-13T06:16:08.000279 | Mallory |
clojurians | clojure | is there a good way to measure how many threads are calling a function at the same time? | 2017-12-13T06:45:34.000496 | Jena |
clojurians | clojure | i'm now abusing java.util.concurrent.Semaphore with more permits than i will ever need, does anyone know a better way? | 2017-12-13T06:46:48.000315 | Jena |
clojurians | clojure | I notice that <https://clojure.org/guides/getting_started> uses an unversioned install script, this is problematic for reproducible builds. Is there an alternative url? | 2017-12-13T07:20:49.000135 | Jodie |
clojurians | clojure | Looks like the expectation is that the linux install script will not be used by packages. But the contents will be replicated into a build step. Got it. | 2017-12-13T07:32:40.000078 | Jodie |
clojurians | clojure | It is versioned and there is a actually a versioned script in the same location as well. I would like it to be used by packages if possible rather than replicating stuff. If you’re working on something, please let me know. | 2017-12-13T08:10:07.000389 | Sonny |
clojurians | clojure | <@Mallory> what's the input data for that code? | 2017-12-13T08:52:19.000045 | Owen |
clojurians | clojure | <@Owen> Hello | 2017-12-13T09:44:10.000053 | Mallory |
clojurians | clojure | i'm in another situation now, if i have set of hash maps like this:
[{:s1 "cool" :p1 [{:name "hello"} {:name "world"}]}, {:s2 "cool2" :p1 [{:name "wow"} {:name "world"}]}] | 2017-12-13T09:45:05.000411 | Mallory |
clojurians | clojure | how can i get the full hash maps which contain "wow" in this paths [MAP-VALS :p1 :name] ? | 2017-12-13T09:45:56.000299 | Mallory |
clojurians | clojure | so in this case i should get : [{:s2 "cool2" :p1 [{:name "wow"} {:name "world"}]}] | 2017-12-13T09:46:14.000420 | Mallory |
clojurians | clojure | i think this is what you're looking for: `(select [ALL (selected? :p1 ALL :name (pred= "wow"))] data)` | 2017-12-13T09:50:25.000364 | Owen |
clojurians | clojure | Logic programming is a tool I use in what I call "code compression". As time goes on and a codebase grows I tend to see high level patterns that I would like to compress. For example, I may have a large XML structure that I'm parsing and I'm using tons of `get-in`s, reducing over the results and emitting them into some other format. | 2017-12-13T10:09:37.000771 | Sandy |
clojurians | clojure | So at a basic level what I try to find are "code compression" algorithms that allow me to express the "what" without the "how". Often this goes beyond stuff like `get-in` or specter as I also need aggregation, advanced predicates, etc. | 2017-12-13T10:10:39.000616 | Sandy |
clojurians | clojure | Most of the time what I end up using is an ad-hoc engine that does just enough to fulfill the needs of a given client, but I'd love to see something more advanced. | 2017-12-13T10:11:46.000052 | Sandy |
clojurians | clojure | Once you have a DSL of sorts that expresses declaratively what you want to do, the next question is "how do I optimize the output of this engine". This also then allows me to separate the "what" from the "how to do it fast". | 2017-12-13T10:12:43.000742 | Sandy |
clojurians | clojure | Instaparse follows this, you express the "how" in the EBNF language, and then the parser engine figures out how to make it fast. If in the future Instaparse figures out how to optimize some construct, I don't have to change my code, I just pull down their new lib. | 2017-12-13T10:13:37.000499 | Sandy |
clojurians | clojure | The same thing could be done in a very simple way with something like get-in. Perhaps get-in could take many paths and then find common sub-paths in the arguments only traversing into children once per unique subpath. | 2017-12-13T10:15:11.000925 | Sandy |
clojurians | clojure | <@Owen> very good thanks :slightly_smiling_face: | 2017-12-13T10:15:46.000032 | Mallory |
clojurians | clojure | and thank you for specter | 2017-12-13T10:16:16.000349 | Mallory |
clojurians | clojure | <@Mallory> sure thing, feel free to jump into the <#C0FVDQLQ5|specter> channel if you have more questions | 2017-12-13T10:18:27.000046 | Owen |
clojurians | clojure | ```
Caused by: java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:3332)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124)
```
Running into this ^ in a project where I previously never had issues with heap space. The stacktrace seems to indicate that I’m trying to print an infinite seq or something like that but there’s nothing in the stacktrace telling me where it’s coming from — anyone suggestions how I could debug this? (full stacktrace: <http://sprunge.us/UUGN>) | 2017-12-13T10:45:12.000376 | Renata |
clojurians | clojure | <@Renata> I'd be tempted to say to look into a sudden grow in size of some external data dependency, assuming your code depending on some and you didn't change anything | 2017-12-13T10:48:45.000551 | Eliana |
clojurians | clojure | could be something leaking slowly | 2017-12-13T10:49:51.000136 | Weston |
clojurians | clojure | having metrics on jvm heap usage helps to spot this kind of things | 2017-12-13T10:50:39.000172 | Weston |
clojurians | clojure | then you can also reduce the size of the heap then enable heap dumps and be ready to crawl into logs, but the few times I had to deal with that, correlation with metrics/commits when it started was enough | 2017-12-13T10:53:29.000557 | Weston |
clojurians | clojure | To my surprise I can’t find any commit that does not produce an OOM exception. :disappointed: I did take a heap dump and there are about 1.1M maps with dates and all kinds of things so these seem to be retained somehow, either because they are printed as the stacktrace seems to indicate or because I’m somehow holding on to the head of a sequence. Do you have any recommendations to figure out where this is happening? | 2017-12-13T11:23:24.000981 | Renata |
clojurians | clojure | I’m really stunned that this issue seems to appear even with older commits | 2017-12-13T11:24:05.000537 | Renata |
clojurians | clojure | <@Renata> do you have access to a memory profiler (like yourkit?) they can often perform memory retention analysis. "1.4mil dates, held by these two references..." | 2017-12-13T11:28:04.000604 | Sandy |
clojurians | clojure | I have no idea what happened but the issue seems to just have gone away, what the heck? :flushed: | 2017-12-13T12:14:53.000617 | Renata |
clojurians | clojure | Heisenbugs, the worst kind. | 2017-12-13T12:23:57.000215 | Bibi |
clojurians | clojure | you could benchmark `(into [] (subvec v ...))` vs `(nth (iterate pop v) n)` | 2017-12-13T12:26:09.000300 | Margaret |
clojurians | clojure | I wonder if vectors are smart about using subvecs via structural sharing | 2017-12-13T12:26:48.000008 | Margaret |
clojurians | clojure | Is there a variant of `partition` that, instead of asking for partitions of size N, I can ask for N partitions? | 2017-12-13T12:29:40.000039 | Daniele |
clojurians | clojure | no but it's easy to write one | 2017-12-13T12:33:41.000078 | Kareen |
clojurians | clojure | <@Daniele> Not that I'm aware of, you'll have to make it yourself. It's presumably not included because in order to have exactly N partitions of roughly equal size, you have to know the size of the entire collection ahead of time, which means it's inherently unable to be lazy | 2017-12-13T12:33:45.000788 | Raul |
clojurians | clojure | the reason why it's not in core is that your function needs to know the lenght of the collection | 2017-12-13T12:33:57.000720 | Kareen |
clojurians | clojure | well, what <@Raul> said :) | 2017-12-13T12:34:03.000409 | Kareen |
clojurians | clojure | <@Kareen> <@Raul> thanks guys. Ended up here:
```
;; adapted from <https://stackoverflow.com/a/2135920>
(defn chunkify
[values n]
(let [cnt (count values)
[k m] [(quot cnt n) (rem cnt n)]]
(for [i (range n)]
(subvec values
(+ (* i k) (min i m))
(+ (* (inc i) k) (min (inc i) m))
))))
``` | 2017-12-13T13:13:32.000415 | Daniele |
clojurians | clojure | Not nearly as pretty as the Python version, but it works :slightly_smiling_face: | 2017-12-13T13:13:54.000312 | Daniele |
clojurians | clojure | wait, am I missing something, why concat? | 2017-12-13T13:15:24.000035 | Margaret |
clojurians | clojure | oh, if I’m not mistaken that concat is a noop | 2017-12-13T13:15:51.000168 | Margaret |
clojurians | clojure | Ah! Yes you're right. | 2017-12-13T13:16:12.000263 | Daniele |
clojurians | clojure | <@Daniele> Why not just compute the `n` that you'd need for `partition-all`? | 2017-12-13T13:17:14.000545 | Randee |
clojurians | clojure | something like ```(defn partition-n-groups [n coll]
(partition-all (int (/ (count coll) n)) coll))``` | 2017-12-13T13:19:11.000447 | Raul |
clojurians | clojure | <@Raul> counter example:
```
(partition-n-groups 3 [1 2 3 4])
``` | 2017-12-13T13:19:51.000298 | Daniele |
clojurians | clojure | Returns:
```
((1) (2) (3) (4))
``` | 2017-12-13T13:20:03.000496 | Daniele |
clojurians | clojure | <@Randee> I actually was initially, but I was running into edge cases like above | 2017-12-13T13:20:20.000532 | Daniele |
clojurians | clojure | yeah, I think you want to round up instead of down | 2017-12-13T13:20:26.000176 | Margaret |
clojurians | clojure | agreed ```(defn partition-n-groups [n coll]
(partition-all (Math/ceil (/ (count coll) n)) coll))``` | 2017-12-13T13:21:38.000111 | Raul |
clojurians | clojure | it’s still off ```(ins)user=> (defn partition-n-groups [n coll]
(partition-all (Math/ceil (/ (count coll) n)) coll))
#'user/partition-n-groups
(ins)user=> (partition-n-groups 3 [1 2 3 4])
((1 2) (3 4))``` | 2017-12-13T13:22:27.000053 | Margaret |
clojurians | clojure | Mhm...I'm afraid rounding just trades one edge case for another :confused: | 2017-12-13T13:22:45.000388 | Daniele |
clojurians | clojure | Which led me to asking you all, and arriving at that Python implementation. | 2017-12-13T13:23:08.000288 | Daniele |
clojurians | clojure | <@Daniele> Well what should it return? The last el dropped or the last element merged into the last collection? | 2017-12-13T13:24:02.000201 | Randee |
clojurians | clojure | <@Randee> it should ideally keep all elements, like `partition-all` does | 2017-12-13T13:24:26.000046 | Daniele |
clojurians | clojure | As far as grouping goes, I'm not too picky. It's fine if an element ends up in any grouping. | 2017-12-13T13:24:56.000039 | Daniele |
clojurians | clojure | <@Daniele> are you trying to guarantee that you 1.) don't drop any elements and 2.) have exactly `n` groups in the output? | 2017-12-13T13:25:06.000009 | Raul |
clojurians | clojure | <@Raul> exactly that. I'm specifically dealing with `n = 3`, and there are guaranteed to be `>= 3` elements in the input coll | 2017-12-13T13:25:40.000271 | Daniele |
clojurians | clojure | I should add that the sort order should remain intact | 2017-12-13T13:27:14.000539 | Daniele |
clojurians | clojure | <@Daniele> interesting problem - I think this solves it ```(defn partition-n
[n coll]
(let [c (count coll)
r (rem c n)
q (quot c n)
N (+ q (if (zero? r) 0 1))]
(partition-all N coll)))``` | 2017-12-13T13:36:48.000385 | Margaret |
clojurians | clojure | perhaps N should be `(if (zero? r) q (inc q))` | 2017-12-13T13:37:27.000157 | Margaret |
clojurians | clojure | (same result) | 2017-12-13T13:37:33.000675 | Margaret |
clojurians | clojure | Can I have a spec conformer for a map that will cherry-pick required keys? Something like:
```
(s/def ::bid (s/merge (s/keys :req-un [::title ::value])
(s/map-of #{::title ::value} any?)))
(s/def ::safe-bid
(s/and
(s/conformer #(select-keys % #{::title ::value}))
::bid))
(s/conform ::safe-bid {:title "reveal" :value 0.1 :extra "foo"})
```
That would return:`=> {:title "reveal" :value 0.1}` | 2017-12-13T13:38:56.000217 | Deneen |
clojurians | clojure | <@Margaret> ah that's _much_ cleaner | 2017-12-13T13:39:08.000204 | Daniele |
clojurians | clojure | could maybe use longer names, but hey it’s so mathy maybe one letter names are OK haha | 2017-12-13T13:39:34.000365 | Margaret |
clojurians | clojure | <@Margaret> hmm...I'm getting:
```
=> (partition-n 3 [1 2 3 4])
((1 2) (3 4))
``` | 2017-12-13T13:41:18.000390 | Daniele |
clojurians | clojure | hmm | 2017-12-13T13:41:34.000107 | Margaret |
clojurians | clojure | clearly I didn’t try enough test cases | 2017-12-13T13:41:49.000354 | Margaret |
clojurians | clojure | _runs to get test.check_ | 2017-12-13T13:41:59.000504 | Daniele |
clojurians | clojure | <@Daniele> aha - there’s no way for partition-all to return a collection of length 3 if given a collection of length 4 | 2017-12-13T13:47:29.000324 | Margaret |
clojurians | clojure | d’oh | 2017-12-13T13:47:32.000917 | Margaret |
clojurians | clojure | Thaaaat could be a problem haha | 2017-12-13T13:48:36.000680 | Daniele |
clojurians | clojure | I bet there’s still an elegant solution though… | 2017-12-13T13:48:50.000417 | Margaret |
clojurians | clojure | Python makes it look so nice... | 2017-12-13T13:49:06.000058 | Daniele |
clojurians | clojure | Practically a one-liner | 2017-12-13T13:49:20.000619 | Daniele |
clojurians | clojure | what is the python version? | 2017-12-13T13:49:39.000196 | Raul |
clojurians | clojure | <@Raul> hm, not sure | 2017-12-13T13:56:28.000321 | Daniele |
clojurians | clojure | Looks to be pretty standard python list comprehension | 2017-12-13T13:57:01.000035 | Daniele |
clojurians | clojure | <https://clojuredocs.org/clojure.core/subvec> <-- O(1) time according to docs | 2017-12-13T14:19:32.000632 | Berry |
clojurians | clojure | Is there a Clojure DSL for specifying parallel computations on tensors that:
on Desktop, compiles to Cuda/OpenCL and on CLJS, compiles to WebAssembly? :slightly_smiling_face: | 2017-12-13T14:21:23.000200 | Berry |
clojurians | clojure | "parallel Tensor Ops" seems like it should be high enough level that it's possible to efficiently target all those platforms | 2017-12-13T14:21:45.000467 | Berry |
clojurians | clojure | right what I am asking is how expensive making a vector out of a subvec is | 2017-12-13T14:22:23.000772 | Margaret |
clojurians | clojure | that may or may not be faster than making a vector out of a list | 2017-12-13T14:22:37.000432 | Margaret |
clojurians | clojure | I thought subvec returned a vector. If so, where is the problem of 'how expensive making a vector out of a subvec is" | 2017-12-13T14:24:39.000385 | Berry |
clojurians | clojure | it doesn’t | 2017-12-13T14:36:06.000475 | Margaret |
clojurians | clojure | oh wait, it isn’t a vector, but might as well be one, never mind! | 2017-12-13T14:36:53.000091 | Margaret |
clojurians | clojure | Are there clojure x videos up anywhere? | 2017-12-13T14:40:04.000104 | Glory |
clojurians | clojure | <https://skillsmatter.com/conferences/8783-clojure-exchange-2017#skillscasts> | 2017-12-13T14:50:01.000560 | Rene |
clojurians | clojure | Thanks for the reminder - I haven't had a chance to watch them yet and was looking for something to watch later :slightly_smiling_face: | 2017-12-13T14:51:11.000640 | Rene |
clojurians | clojure | <@Daniele> I made a sequence version of `n-partitions`, by re-using the math from the python/vector version. I wouldn't really call it an improvement in clarity though.
```
(defn n-partitions
[n coll]
(let [cnt (count coll)
[q r] [(quot cnt n) (rem cnt n)]
partition-size (fn [i]
(- (+ (* (inc i) q) (min (inc i) r))
(+ (* i q) (min i r))))]
(->> (range n)
(reductions (fn [[_ more] i]
(split-at (partition-size i) more))
[nil coll])
(rest)
(map first))))
``` | 2017-12-13T15:28:03.000532 | Giovanna |
clojurians | clojure | at the current state of clojure.spec, is it possible to spec multimethods? | 2017-12-13T16:18:10.000112 | Ahmad |
clojurians | clojure | I found a weird thing with `some`. I rewrote it using `reduce` and found it was much faster:
```
(defn find-first
[pred vals]
(reduce
(fn [_ v]
(when (pred v)
(reduced v)))
nil
vals))
(time (some identity (repeat 10000000 nil))) ;; 250 ms
(time (find-first identity (repeat 10000000 nil))) ;; 40 ms
``` | 2017-12-13T16:24:55.000168 | Johana |
clojurians | clojure | <@Johana> Don't use repeat to benchmark things. Real code barely uses it. | 2017-12-13T16:32:27.000386 | Randee |
clojurians | clojure | <@Randee> ok, I tried it with other collections too, same thing | 2017-12-13T16:32:52.000080 | Johana |
clojurians | clojure | <@Johana> Yeah some uses first/next which isnt' all that fast. Reduce is usually faster. I see a 2x factor | 2017-12-13T16:33:30.000509 | Randee |
clojurians | clojure | ```
(time (some #(when (> ^long % 10000000) %) (range))) ;; 558 ms
(time (find-first #(> ^long % 10000000) (range))) ;; 95 ms
``` | 2017-12-13T16:36:14.000530 | Johana |
clojurians | clojure | re: find-first transducer version: <https://github.com/weavejester/medley/blob/1.0.0/src/medley/core.cljc#L6> | 2017-12-13T17:07:11.000268 | Cecile |
clojurians | clojure | cool | 2017-12-13T17:11:01.000238 | Johana |
clojurians | clojure | Is there a Clojure killer applications? For example, Scala has a renowned Akka. | 2017-12-13T17:26:24.000161 | Heriberto |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.