workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
clojurians | clojure | stop this madness :scream: | 2017-11-28T19:13:40.000102 | Aldo |
clojurians | clojure | <@Aldo> the docs specifically say it’s allowed… but it definitely *feels* weird | 2017-11-28T19:20:50.000108 | Margaret |
clojurians | clojure | That's the thing about having a library that processes other people's code, it has to handle any possibility | 2017-11-28T19:32:49.000111 | Herlinda |
clojurians | clojure | Hey all. If anyone else is interested in having official New Relic support for Clojure, please upvote my support ticket. :slightly_smiling_face:
<https://discuss.newrelic.com/t/feature-idea-current-state-of-clojure-instrumentation/53105> | 2017-11-28T19:43:14.000302 | Elliott |
clojurians | clojure | I’d prefer to see this done via their <http://opentracing.io|opentracing.io> compatibility. The opentracing api is pretty easy to deal with via java interop. I have been messing with a clojure wrapper as well, but pretty much it all converges to a `with-open` that opens the trace context, and some (still being debated) machinery to propagate tracing contexts in-process across threads and such. | 2017-11-28T19:58:27.000195 | Kyung |
clojurians | clojure | <https://blog.newrelic.com/2017/09/13/distributed-tracing-opentracing/> | 2017-11-28T20:02:29.000032 | Kyung |
clojurians | clojure | <@Kyung> Interesting. Thanks, will check it out | 2017-11-28T20:05:08.000196 | Elliott |
clojurians | clojure | The downside to opentracing is how early it is. Elements of the api are not settled, like the in-process propagation thing I mentioned, but basic tracing is in place and multiple backends are available. | 2017-11-28T20:23:29.000198 | Kyung |
clojurians | clojure | warning: clojure n00b here.
i'm trying to process data from a gzipped file that has JSON documents concatenated together in it (no delimited, not even a newline). so far I have two functions that can gunzip the file and produce a reader. i've been trying to find ways to parse this into JSON.
one idea is to process the character stream from the reader, keep track of curly braces and emit/print when the i'm at the appropriate place ("}{"). but I'm having a hard time keeping track of state in absence of mutable variables.
another idea is to use something like re-find but it works only on strings. I don't want to read in the while file since the data I have is too large and I'd rather process it lazily since i plan to run this in aws lambda (limited memory).
the functions I have so far (apart various broken experiments):
```
(defn in [f]
(->
(<http://clojure.java.io/input-stream|clojure.java.io/input-stream> f)
(java.util.zip.GZIPInputStream.)
(<http://clojure.java.io/reader|clojure.java.io/reader>)))
(defn char-seq
[^java.io.Reader rdr]
(let [chr (.read rdr)]
(if (>= chr 0)
(cons (char chr) (lazy-seq (char-seq rdr))))))
```
i could make the process and algorithm work in python (very slow) but would prefer to use clojure. i've spent too much time (2 days) trying to figure out a way but no luck so far.. any pointers/advice at all would be greatly appreciated. | 2017-11-28T21:16:42.000038 | Kathe |
clojurians | clojure | You're on the right track <@Kathe>! You have the reader all ready to go. Let's focus on the other half of the problem: parsing a series of JSON values (i.e. concatenated) | 2017-11-28T21:25:26.000296 | Guillermo |
clojurians | clojure | Take an example of concatenated JSON and represent it not as a stream but as a string: | 2017-11-28T21:26:08.000184 | Guillermo |
clojurians | clojure | ```(def example "{}{}{}")``` | 2017-11-28T21:26:19.000059 | Guillermo |
clojurians | clojure | What you want at the end is a seq or vector like so: | 2017-11-28T21:26:33.000218 | Guillermo |
clojurians | clojure | ```(def expected [{}{}{}])``` | 2017-11-28T21:26:45.000101 | Guillermo |
clojurians | clojure | i.e. a clojure sequence of 3 empty, clojure, maps. | 2017-11-28T21:27:11.000059 | Guillermo |
clojurians | clojure | To parse the example string, we want to turn this _back_ into a stream, because ~the~ most JSON parsers take a stream (i.e. java Reader) as their input. And you also said you want to parse this lazily. | 2017-11-28T21:28:10.000049 | Guillermo |
clojurians | clojure | So import cheshire (a common JSON reading library): | 2017-11-28T21:28:56.000054 | Guillermo |
clojurians | clojure | ```user=> (require '[cheshire.core :as json])
nil
user=> (doc json/parse-stream)
-------------------------
cheshire.core/parse-stream
([rdr] [rdr key-fn] [rdr key-fn array-coerce-fn])
If multiple objects (enclosed in a top-level `{}' need to be parsed lazily,
see parsed-seq.
``` | 2017-11-28T21:29:42.000226 | Guillermo |
clojurians | clojure | cheshire is ready :slightly_smiling_face: | 2017-11-28T21:29:52.000255 | Kathe |
clojurians | clojure | I've elided some useless docs, and it's pointing us to `parsed-seq` for your/this use case. | 2017-11-28T21:30:08.000146 | Guillermo |
clojurians | clojure | ```user=> (doc json/parsed-seq)
-------------------------
cheshire.core/parsed-seq
([reader] [reader key-fn] [reader key-fn array-coerce-fn])
Returns a lazy seq of Clojure objects corresponding to the JSON read from
the given reader. The seq continues until the end of the reader is reached.
``` | 2017-11-28T21:30:27.000241 | Guillermo |
clojurians | clojure | OK, we got wheels. | 2017-11-28T21:30:37.000131 | Guillermo |
clojurians | clojure | Note that because it returns us a lazy seq, you'll have to consume it fully before closing the underlying Reader. | 2017-11-28T21:31:26.000025 | Guillermo |
clojurians | clojure | Usually you close the reader when it leaves lexical scope, using `with-open` | 2017-11-28T21:31:55.000059 | Guillermo |
clojurians | clojure | `(with-open [r (some-stream)] (do all the stuff))` | 2017-11-28T21:32:13.000150 | Guillermo |
clojurians | clojure | (This doesn't mean you have to load the whole stream eagerly into memory, we'll still be mindful of efficiency) | 2017-11-28T21:33:17.000203 | Guillermo |
clojurians | clojure | Typical ways to consume the seq fully are:
1. do some collection operations using the seq, and wrap that code in `doall`
2. `reduce` / `transduce` (collecting accumulation)
3. `doseq` | 2017-11-28T21:35:21.000026 | Guillermo |
clojurians | clojure | 4. `(into [])` or `vec` wrapping collection operations (variation of 1.) | 2017-11-28T21:36:02.000204 | Guillermo |
clojurians | clojure | Ok... so to make this concrete let's parse that example above. (I'll leave the task of glueing it to the GZipReader to you) | 2017-11-28T21:37:05.000242 | Guillermo |
clojurians | clojure | ```
user=> (with-open [r (java.io.StringReader. example)] (vec (json/parsed-seq r)))
[{} {} {}]
``` | 2017-11-28T21:38:22.000019 | Guillermo |
clojurians | clojure | ```
user=> (= *1 expected)
true
``` | 2017-11-28T21:39:18.000175 | Guillermo |
clojurians | clojure | <@Guillermo> thank you so much! this is very educational. that `parsed-seq` function is great. that combined with one of the 4 things you listed should do the trick.
i'm trying to digest what you said and seeing some light. i'll come back after a little while after I've tried a few things.. thank you again. | 2017-11-28T21:45:02.000223 | Kathe |
clojurians | clojure | ya <@Kathe>. clojure is stupidly fun | 2017-11-28T21:45:24.000121 | Guillermo |
clojurians | clojure | enjoy | 2017-11-28T21:45:41.000282 | Guillermo |
clojurians | clojure | it is but it's incredibly humbling too. | 2017-11-28T21:46:56.000034 | Kathe |
clojurians | clojure | i really like how you built that small example to test and show the idea. | 2017-11-28T21:47:54.000207 | Kathe |
clojurians | clojure | my brain needs to be disinfected of procedural thinking. unlearning is hard. | 2017-11-28T21:51:35.000108 | Kathe |
clojurians | clojure | i don't know whether to be happy or be sad... after hours upon hours of frustration, all of it works in just a couple of lines. | 2017-11-28T22:14:51.000142 | Kathe |
clojurians | clojure | you're awesome! <@Guillermo> | 2017-11-28T22:15:06.000115 | Kathe |
clojurians | clojure | <@Kathe> I think one of the things with Clojure is that simplicity is king. If you're struggling with a problem and your code seems overly complex, then there's probably a much simpler, more idiomatic solution :slightly_smiling_face: | 2017-11-28T22:31:31.000042 | Daniell |
clojurians | clojure | i'll keep that in mind. | 2017-11-28T22:35:27.000034 | Kathe |
clojurians | clojure | on that a related question. i don't have any local user group or colleagues who do clojure. i was super frustrated, had a headache on, dozens of tabs open and what not.. and had no one I could ask. normally I hesitate to bother but i find that my progress is also super slow. when is it appropriate (or inappropriate) to come ask for help here? | 2017-11-28T22:40:26.000008 | Kathe |
clojurians | clojure | <@Kathe> <#C053AK3F9|beginners> | 2017-11-28T23:19:22.000107 | Cecile |
clojurians | clojure | sounds like the place for me. thanks <@Cecile> | 2017-11-28T23:31:17.000136 | Kathe |
clojurians | clojure | Edit: Sorry I notice that there's a dedicated aws-lambda channel, I'll move my question there | 2017-11-29T04:13:37.000030 | Marvin |
clojurians | clojure | i see that there's brandon bloom's backtick lib, but is there any way to make clojure not impose namespaces on syntax-quoted forms? | 2017-11-29T12:01:31.000563 | Willow |
clojurians | clojure | qualifying symbols with a namespace is half of the point of syntax quote | 2017-11-29T12:03:19.000490 | Aldo |
clojurians | clojure | you can always regular quote the symbols you don't want syntax quoted
```
`(~'a)
=> (a)
``` | 2017-11-29T12:04:07.000359 | Aldo |
clojurians | clojure | i need it without it to send to datomic | 2017-11-29T12:04:25.000109 | Willow |
clojurians | clojure | so all of the unification symbols have to be marked. quite a pain and ugly | 2017-11-29T12:11:48.000666 | Willow |
clojurians | clojure | ```
`[:find [(~'pull ~'?task ~tasks/task-shape) ...]
:in ~'$ ~'?docref
:where
[~'?task :property1 ~'?docref]
[~'?task :property2 ~'?tc]
[~'?tc :tags "tag"]]
``` | 2017-11-29T12:12:26.000086 | Willow |
clojurians | clojure | why not use regular quote? | 2017-11-29T12:14:19.000438 | Aldo |
clojurians | clojure | the tasks/task-shape. I'm trying to put the query for what a task looks like in one place and then let others query against this common shape however they like | 2017-11-29T12:14:47.000415 | Willow |
clojurians | clojure | oh I see you're using one var in there | 2017-11-29T12:14:50.000239 | Aldo |
clojurians | clojure | so i need to resolve | 2017-11-29T12:14:52.000759 | Willow |
clojurians | clojure | yeah | 2017-11-29T12:14:53.000342 | Willow |
clojurians | clojure | probably easiest to build it up in pieces I guess, but yeah bit annoying
```
[:find [`(~'pull ~'?task ~tasks/task-shape) ...]
:in '$ '?docref
:where
'[?task :property1 ?docref]
'[?task :property2 ?tc]
'[?tc :tags "tag"]]
``` | 2017-11-29T12:17:29.000410 | Aldo |
clojurians | clojure | yeah good point. use the vectors and keywords to my advantage. still not sold on it. gonna roll it around a bit | 2017-11-29T12:18:08.000166 | Willow |
clojurians | clojure | <@Willow> it seems like it would be easier to just not use ` at all there
```[:find [(list 'pull '?task tasks/task-shape) ...]
:in '$ ?docref
:where
'[?task :property1 :docref]
'[?task :property2 ?tc]
'[?tc :tags "tag"]]``` | 2017-11-29T12:19:49.000789 | Margaret |
clojurians | clojure | <@Willow> I just use <https://github.com/gfredericks/misquote/blob/master/src/misquote/core.clj> for that. | 2017-11-29T12:20:57.000415 | Randee |
clojurians | clojure | thanks. that's looking the cleanest so far. just makes me nervous that this stuff just silently and happily fails on datomic if its namespaced. i'm deciding which is worse the super important syntax or the duplication of the structure | 2017-11-29T12:20:58.000095 | Willow |
clojurians | clojure | thanks <@Randee> i saw bblooms backtick as well. any reason to choose one over the other that you know of? I think i saw brandon handles gensyms but not sure how important that is for my purposes | 2017-11-29T12:22:38.000255 | Willow |
clojurians | clojure | <@Willow> Not sure, but I use the above for exactly that purpose: Creating datomic queries. It works well. Though I changed it slightly to make Cursive happy | 2017-11-29T12:23:34.000535 | Randee |
clojurians | clojure | well thanks for the suggestion. gonna mull on it | 2017-11-29T12:23:49.000437 | Willow |
clojurians | clojure | <@Willow> Here the full example: <https://gist.github.com/rauhs/d2575e77e6e063ae94abbd9f1bca226d> | 2017-11-29T12:25:04.000640 | Randee |
clojurians | clojure | are type hints (in clojure) used only to avoid introspection? | 2017-11-29T14:02:04.000360 | Merrie |
clojurians | clojure | yes, type hints are only to avoid reflection | 2017-11-29T14:03:46.000506 | Raul |
clojurians | clojure | or is there some way to enforce them, apart from `{:pre [(instance? MyRecord arg)]}`? | 2017-11-29T14:04:03.000434 | Merrie |
clojurians | clojure | if you're interested in enforcing types, you should probably consider spec or plumatic schema | 2017-11-29T14:04:36.000413 | Raul |
clojurians | clojure | or pre/post/raw assertions, if you're only using them on occasion | 2017-11-29T14:05:00.000319 | Raul |
clojurians | clojure | I use spec, but I also have a bunch of defrecords hanging around, wanted to squeeze some extra value out of those | 2017-11-29T14:05:47.000228 | Merrie |
clojurians | clojure | right now I am getting familiar with a module in an app, and sprinkling type hints all over fn signatures helps to understand teh mess, also IDE's "show usages" | 2017-11-29T14:07:48.000676 | Merrie |
clojurians | clojure | but it seems like specs is the ultimate way to go, if records are not really used for extending protocols, etc. | 2017-11-29T14:08:38.000493 | Merrie |
clojurians | clojure | Spec is the way to go with this stuff. You can turn it on and off. I think you are going to regret extensive manual assertions and hints. | 2017-11-29T14:09:14.000065 | Guillermo |
clojurians | clojure | getting decent spec coverage and "infrastructure" is a project in itself, though | 2017-11-29T14:09:30.000666 | Merrie |
clojurians | clojure | it can be a lot of work, but pays off immensely | 2017-11-29T14:09:51.000152 | Guillermo |
clojurians | clojure | yeah, agree on manual assertions | 2017-11-29T14:09:57.000006 | Merrie |
clojurians | clojure | esp. wrt generative testing | 2017-11-29T14:10:01.000130 | Guillermo |
clojurians | clojure | True | 2017-11-29T14:10:04.000118 | Merrie |
clojurians | clojure | A :: map
B :: set
I want to remove all (k,v) pairs from A where k is in B
is the best way to do this `(apply dissoc A B)`
or is there a more efficient way ? | 2017-11-29T14:38:29.000362 | Berry |
clojurians | clojure | <@Berry> `(reduce dissoc A B)` | 2017-11-29T14:43:34.000105 | Owen |
clojurians | clojure | reduce won't perform better here | 2017-11-29T14:44:30.000084 | Kareen |
clojurians | clojure | ```
user=> (def A {:a 1 :b 2 :c 3})
#'user/A
user=> (def B #{:a :c})
#'user/B
user=> (time
#_=> (dotimes [_ 1000000]
#_=> (reduce dissoc A B)
#_=> ))
"Elapsed time: 120.139233 msecs"
nil
user=> (time
#_=> (dotimes [_ 1000000]
#_=> (apply dissoc A B)
#_=> ))
"Elapsed time: 335.459923 msecs"
``` | 2017-11-29T14:47:11.000189 | Owen |
clojurians | clojure | interesting | 2017-11-29T14:50:32.000390 | Kareen |
clojurians | clojure | I would imagine that with a larger sized B apply would evenually win, as the vararg version can iterate over the coll w/o having to pay an invocation price | 2017-11-29T14:51:19.000383 | Kareen |
clojurians | clojure | yeah seems heavily dependent on the size of A and B | 2017-11-29T14:51:55.000486 | Aldo |
clojurians | clojure | but maybe the seq path is that much slower than the native reduce of sets | 2017-11-29T14:51:59.000470 | Kareen |
clojurians | clojure | from the peanut gallery over here: neither choice will/should dominate in your codebase | 2017-11-29T14:52:43.000577 | Guillermo |
clojurians | clojure | ```
(def s1 (range 1000000))
(def s2 (map #(* 2 %) (range 500000)))
(def m (into {} (for [x s1] [x x])))
(time (do (apply dissoc m s2)
nil))
(time (do (reduce dissoc m s2)
nil))
```
I'm not getting a noticable difference | 2017-11-29T14:53:18.000154 | Berry |
clojurians | clojure | you're measuring cold code on the JVM | 2017-11-29T14:54:18.000267 | Guillermo |
clojurians | clojure | need some JITing action to make a better benchmark | 2017-11-29T14:54:37.000057 | Guillermo |
clojurians | clojure | yeah, using criterium bench now | 2017-11-29T14:54:51.000569 | Berry |
clojurians | clojure | i'm still getting used to the concept of having to 'warmup' the system first | 2017-11-29T14:55:16.000435 | Berry |
clojurians | clojure | ```
(def s1 (range 1000000))
(def s2 (map #(* 2 %) (range 500000)))
(def m (into {} (for [x s1] [x x])))
(cc/quick-bench
(do (apply dissoc m s2)
nil))
(comment
Execution time mean : 456.384541 ms
Execution time std-deviation : 69.565195 ms
Execution time lower quantile : 411.034707 ms ( 2.5%)
Execution time upper quantile : 545.198448 ms (97.5%)
Overhead used : 2.943666 ns)
(cc/quick-bench
(do (reduce dissoc m s2)
nil))
(comment
Execution time mean : 469.385020 ms
Execution time std-deviation : 83.522059 ms
Execution time lower quantile : 393.009549 ms ( 2.5%)
Execution time upper quantile : 546.717419 ms (97.5%)
Overhead used : 2.943666 ns)
``` | 2017-11-29T14:57:00.000008 | Berry |
clojurians | clojure | what surprises me most: (apply dissoc ...) doesn't cause a stack overflow for having so many args on the 'stack frame' | 2017-11-29T14:58:03.000101 | Berry |
clojurians | clojure | I can explain that | 2017-11-29T14:58:27.000069 | Aldo |
clojurians | clojure | <https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IFn.java> | 2017-11-29T14:58:50.000057 | Aldo |
clojurians | clojure | after 20 arguments they just get shoved in an array | 2017-11-29T14:59:00.000500 | Aldo |
clojurians | clojure | lol, there's something hilarious about that code | 2017-11-29T15:00:08.000094 | Berry |
clojurians | clojure | with criterium not seeing any cases where `apply` version outperforms `reduce` version | 2017-11-29T15:05:52.000170 | Owen |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.