workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
clojurians | clojure | Serialization libraries generally have a way to teach them how to serialize opaque objects. cheshire allows you to extend a protocol to achieve that, not sure what c.data.json gives you as an extension point | 2017-11-28T10:38:58.000394 | Guillermo |
clojurians | clojure | Thank you, I see now that even a generic exception fails with the same issue:
```
(try (throw (Exception. "hi"))
(catch Exception e
(json/write-str (Throwable->map e))))
=> Exception Don't know how to write JSON of class java.lang.Class clojure.data.json/write-generic (json.clj:385)
``` | 2017-11-28T10:40:05.000751 | Jacalyn |
clojurians | clojure | looks like they allow a protocol too | 2017-11-28T10:41:45.000633 | Guillermo |
clojurians | clojure | ```
(extend-protocol JSONWriter
java.lang.Class
(-write [c out]
(let [representation (do something to the class c)]
(.print ^PrintWriter out representation))))
``` | 2017-11-28T10:43:42.000265 | Guillermo |
clojurians | clojure | you'll need to import JSONWriter from c.d.json and PrintWriter from <http://java.io|java.io> | 2017-11-28T10:44:18.000396 | Guillermo |
clojurians | clojure | > clojure.core/Throwable->map formerly returned StackTraceElements which were later handled by the printer. Now the StackTraceElements are converted to data such that the return value is pure Clojure data, as intended. | 2017-11-28T10:46:44.000005 | Guillermo |
clojurians | clojure | ^ Tidbit from the Clojure 1.9.0 release notes | 2017-11-28T10:46:52.000677 | Guillermo |
clojurians | clojure | Sounds good, thank you. | 2017-11-28T10:47:47.000444 | Jacalyn |
clojurians | clojure | Is there something like `promise` where delivery can happen multiple times and deref just returns the last delivered value? | 2017-11-28T15:24:47.000354 | Johana |
clojurians | clojure | maybe core.async | 2017-11-28T15:25:04.000556 | Johana |
clojurians | clojure | but I want everybody to be able to deref, without emptying | 2017-11-28T15:25:30.000487 | Johana |
clojurians | clojure | atom and reset! | 2017-11-28T15:25:30.000596 | Rebeca |
clojurians | clojure | or any mutable value | 2017-11-28T15:25:47.000053 | Rebeca |
clojurians | clojure | mutable reference | 2017-11-28T15:25:54.000344 | Rebeca |
clojurians | clojure | that is just last write wins | 2017-11-28T15:26:02.000671 | Rebeca |
clojurians | clojure | the volatile reference might work great for that too | 2017-11-28T15:26:32.000128 | Rebeca |
clojurians | clojure | <https://dev.clojure.org/jira/browse/CLJ-1512> | 2017-11-28T15:27:18.000287 | Rebeca |
clojurians | clojure | but atom reads don’t block and I need that too | 2017-11-28T15:27:19.000106 | Johana |
clojurians | clojure | I think the implications behind "delivery can happen multiple times" rule out volatile. sounds like an atom though | 2017-11-28T15:27:22.000159 | Aldo |
clojurians | clojure | hello everyone, id like to to spawn 4 threads in paralallel to do some IO, i dont need to get data back from those threads, whats the best way to achieve this besides
```
(thread ....)
(thread ..)
...
(thread ...)
``` | 2017-11-28T15:27:36.000111 | Amado |
clojurians | clojure | "delivery" just means a write | 2017-11-28T15:27:37.000215 | Rebeca |
clojurians | clojure | I need the deref to block | 2017-11-28T15:27:52.000098 | Johana |
clojurians | clojure | like with promise | 2017-11-28T15:27:58.000678 | Johana |
clojurians | clojure | I could use a promise with an atom, that would work | 2017-11-28T15:28:37.000036 | Johana |
clojurians | clojure | and double deref | 2017-11-28T15:28:44.000726 | Johana |
clojurians | clojure | I meant that "delivery can happen multiple times" says to me that it's multithreaded, meaning volatile is a bad choice :slightly_smiling_face: | 2017-11-28T15:28:46.000621 | Aldo |
clojurians | clojure | if you are already using core.async (which I guess you are from the use of thread) I would look at pipeline-blocking | 2017-11-28T15:28:52.000107 | Rebeca |
clojurians | clojure | <@Rebeca>, my mistake, i was talking about `clojure.core/future` which spawns a thread ..
do you think its worth to turn my `vector` to a `core.async ` `queue` and use `pipe-line` blocking | 2017-11-28T15:32:56.000310 | Amado |
clojurians | clojure | ? | 2017-11-28T15:32:57.000277 | Amado |
clojurians | clojure | it depends, I might start looking at using Executors directly too instead of using clojure.core/future | 2017-11-28T15:34:10.000633 | Rebeca |
clojurians | clojure | like, do you want to have 4 threads that a re-used for doing io, or do you want to spin up 4 threads each time, does the io return a result, and do you need those results in order or not | 2017-11-28T15:35:09.000437 | Rebeca |
clojurians | clojure | i trully dont care about the result, and i wont reuse anything, those threads perform their work and die silently | 2017-11-28T15:36:05.000002 | Amado |
clojurians | clojure | This works I think.
```
(let [p (promise)]
(defn last-val [] @@p)
(defn reset-val! [v]
(or (deliver p (atom v))
(reset! @@p v))))
(future (println (last-val)))
(reset-val! 10)
(reset-val! 11)
``` | 2017-11-28T15:42:04.000313 | Johana |
clojurians | clojure | I feel like I'm missing something simple here, but has anyone ever implemented a file-tailing algorithm in Clojure? That is, as new lines are written to a file, you process them in your Clojure code? It seems that just opening a reader gets me a snapshot of the file at opening time. | 2017-11-28T15:42:33.000273 | Quincy |
clojurians | clojure | there are promise-chans in core.async that kinda resemble this | 2017-11-28T15:43:01.000349 | Guillermo |
clojurians | clojure | you can fulfill them once and they provide their value immediately forever | 2017-11-28T15:43:15.000042 | Guillermo |
clojurians | clojure | <@Guillermo> I need to ‘fill’ them multiple times | 2017-11-28T15:43:47.000355 | Johana |
clojurians | clojure | <@Quincy> <https://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/input/Tailer.html> or google Java file tailing | 2017-11-28T15:45:00.000027 | Guillermo |
clojurians | clojure | ah, so basically I need interop. I guess I should go ask the planck folks then since I'm in a planck / cljs context. :slightly_smiling_face: Thanks for the pointer! | 2017-11-28T15:46:03.000231 | Quincy |
clojurians | clojure | no problem. cljs should be similar, but obviously asyncio | 2017-11-28T15:46:25.000248 | Guillermo |
clojurians | clojure | I'm with hiredman, sounds like last-write-wins with an atom | 2017-11-28T15:46:33.000496 | Guillermo |
clojurians | clojure | <@Guillermo> I need to block on the first deref when it’s still not initialized. | 2017-11-28T15:47:21.000675 | Johana |
clojurians | clojure | promise an atom? | 2017-11-28T15:47:33.000359 | Guillermo |
clojurians | clojure | <@Guillermo> See my above code. It’s the other way around. Promise in atom doesn’t work, because you can only delivery to a promise once. | 2017-11-28T15:48:08.000500 | Johana |
clojurians | clojure | I guess that's your example above. Seems like the xy problem -- I need to know _why_ | 2017-11-28T15:48:34.000060 | Guillermo |
clojurians | clojure | Yeah, I might not need it, I’ll think about it some more. thanks. | 2017-11-28T15:51:16.000195 | Johana |
clojurians | clojure | <@Johana> what about checking if the atom is nil, and if so putting a watch on the atom that triggers your thing if the new value is non-nil, and then removing the watch inside the watch callback? | 2017-11-28T16:11:28.000434 | Margaret |
clojurians | clojure | or maybe you even want to always want to ignore the current value, and only run your action when the value changes, and `add-watch` is what you want directly | 2017-11-28T16:11:52.000279 | Margaret |
clojurians | clojure | > what about checking if the atom is nil
this is hard to make thread safe without compare-and-set!
I don’t need a watch. | 2017-11-28T16:12:46.000008 | Johana |
clojurians | clojure | the xy about this: I need to prepare some data in the background and I want the first web request to wait for this thing to be ready. It might be refreshed later. | 2017-11-28T16:13:46.000625 | Johana |
clojurians | clojure | with a watch, you can ensure your code doesn’t return until the value is ready | 2017-11-28T16:15:23.000098 | Margaret |
clojurians | clojure | or, use an agent instead of an atom and use await | 2017-11-28T16:15:39.000450 | Margaret |
clojurians | clojure | (well, watch plus delay or promise you can block on that is) | 2017-11-28T16:16:13.000304 | Margaret |
clojurians | clojure | and really, if all you need is to prepare data in the background, why not just use `future` ? | 2017-11-28T16:16:45.000162 | Margaret |
clojurians | clojure | > just use ‘future’
a future cannot be updated | 2017-11-28T16:17:24.000448 | Johana |
clojurians | clojure | why does it need to be updated? why can’t you just make a new value? | 2017-11-28T16:17:44.000291 | Margaret |
clojurians | clojure | and if you have async updates multiple threads wait on, that would happen repeatedly, `await` on an agent sounds like it maps directly to that | 2017-11-28T16:18:26.000060 | Margaret |
clojurians | clojure | `(def a (agent)) (await a) ;;=> nil` | 2017-11-28T16:19:52.000024 | Johana |
clojurians | clojure | right, there are no pending actions on it | 2017-11-28T16:20:01.000396 | Margaret |
clojurians | clojure | atom and swap! with clojure.lang.PersistentQueue | 2017-11-28T16:20:34.000074 | Cecilia |
clojurians | clojure | oh crap, I was on history | 2017-11-28T16:20:46.000209 | Cecilia |
clojurians | clojure | forget that | 2017-11-28T16:20:49.000213 | Cecilia |
clojurians | clojure | Maybe we should switch to a thread as to not flood this channel with this topic, it’s getting kind of long | 2017-11-28T16:21:07.000839 | Johana |
clojurians | clojure | what I don’t understand is how you would know when a is “ready” and when it isn’t | 2017-11-28T16:21:43.000319 | Margaret |
clojurians | clojure | <@Margaret> Everything after the first init is fine | 2017-11-28T16:21:57.000229 | Johana |
clojurians | clojure | This works: <https://clojurians.slack.com/archives/C03S1KBA2/p1511901724000313>
Just wondered if there is some other primitive I could use. | 2017-11-28T16:22:59.000745 | Johana |
clojurians | clojure | But I’m not even sure anymore if I want to do it like this, so it’s ok, I’ll think about it some more | 2017-11-28T16:23:43.000773 | Johana |
clojurians | clojure | I think you're on the right track | 2017-11-28T16:24:55.000131 | Sandy |
clojurians | clojure | maybe something with a count-down-latch? (I may be thinking of the wrong primitive) | 2017-11-28T16:25:28.000482 | Sandy |
clojurians | clojure | I think you have an extra `@` on that reset! - but otherwise that is sensible | 2017-11-28T16:25:59.000267 | Margaret |
clojurians | clojure | Or if you want to drop to Java you could due this with Thread.wait, notify and clojure's `locking` | 2017-11-28T16:26:32.000082 | Sandy |
clojurians | clojure | 1) get the value (non locking)
2) if the value is not a sentinel return it
3) Lock and check if the value is still a sentinel
4) If so, add yourself to a pending threads queue and sleep | 2017-11-28T16:28:14.000528 | Sandy |
clojurians | clojure | the producer then simply sets the value to != a sentinel and wakes all the pending threads. Future writers can ignore the pending threads list | 2017-11-28T16:28:43.000264 | Sandy |
clojurians | clojure | might be worth looking at Claypoole even if your current requirements are minimal right now…. <https://github.com/TheClimateCorporation/claypoole> | 2017-11-28T16:32:55.000117 | Kyung |
clojurians | clojure | `(.setLevel (Logger/getLogger "org.flywaydb") Level/WARNING)` this works (silent DEBUG/INFO logs) unless add to project.clj `[org.slf4j/slf4j-simple "1.7.25"]`.
How can i make silent this logs? | 2017-11-28T16:36:59.000573 | Gladys |
clojurians | clojure | thanks! some stuff to consider | 2017-11-28T16:49:01.000314 | Johana |
clojurians | clojure | Is there a reason why `zipmap` doesn’t a transient under the hood? | 2017-11-28T17:08:15.000410 | Johana |
clojurians | clojure | probably not, there's a few places in Clojure that could still use some transient love | 2017-11-28T17:10:56.000056 | Sandy |
clojurians | clojure | yeah I think a patch with benchmarks for that would probably be accepted | 2017-11-28T17:12:11.000137 | Aldo |
clojurians | clojure | I ran a quick benchmark and for 1000 keys there’s only a drop from 250 to 213 ns | 2017-11-28T17:15:45.000185 | Johana |
clojurians | clojure | Probably because creating a new map from an existing map using assoc is very efficient already | 2017-11-28T17:16:10.000109 | Johana |
clojurians | clojure | yeah I got a measurable difference but not a particularly important one | 2017-11-28T17:17:47.000007 | Aldo |
clojurians | clojure | I tested this because I wanted to know the performance difference between using map literals and zipmap:
```
(def f (fn [[a b num]]
#_=> {:a a
#_=> :b b
#_=> :num num}))
(def g (partial zipmap [:a :b :num]))
(quick-bench (f ["a" "b" 1])) ;;=> 22 ns
(quick-bench (g ["a" "b" 1])) ;;=> 250 ns
``` | 2017-11-28T17:19:12.000123 | Johana |
clojurians | clojure | there's a ticket for this already | 2017-11-28T17:20:47.000330 | Guillermo |
clojurians | clojure | <https://dev.clojure.org/jira/browse/CLJ-1005> | 2017-11-28T17:21:05.000039 | Guillermo |
clojurians | clojure | There was a ticket for making `merge` faster CLJ-1458 but it could use some love, starting with a decent set of benchmarks | 2017-11-28T17:24:56.000145 | Guillermo |
clojurians | clojure | I would like someone to give that a whack. Keeping in mind that merge 1) preserves metadata 2) and because it is based on conj, happens to take either a mapentry, vector, or maps as arguments | 2017-11-28T17:26:33.000104 | Guillermo |
clojurians | clojure | `(merge {} [:a :b] {:c :d}) => {:a :b :c :d}` | 2017-11-28T17:27:41.000015 | Guillermo |
clojurians | clojure | need to go back to basics with that ticket and just start with a benchmark harness. | 2017-11-28T17:28:21.000420 | Guillermo |
clojurians | clojure | <https://dev.clojure.org/jira/browse/CLJ-1458> | 2017-11-28T17:28:36.000405 | Guillermo |
clojurians | clojure | Oh why am I talking with prose: <@Sonny> do you have a `spec` lying around for c.c/merge? | 2017-11-28T17:29:49.000297 | Guillermo |
clojurians | clojure | wow, I'm pulling my hair out over this issue, when I create a reader at the repl this form parses correctly, but when I call a function on the form it throws an error. I'm about to hit the road so hopefully the comments on the ticket are clear <https://github.com/gdeer81/marginalia/issues/165> | 2017-11-28T17:52:27.000196 | Herlinda |
clojurians | clojure | it's such an edge case but I can't let it go | 2017-11-28T17:53:29.000012 | Herlinda |
clojurians | clojure | ```;; A symbol string begins with a non-numeric character and can contain
;; alphanumeric characters and *, +, !, -, _, and ?. (see
;; <http://clojure.org/reader> for details).``` | 2017-11-28T18:40:14.000197 | Margaret |
clojurians | clojure | ~I would expect `:` inside a symbol to work by accident, and any bugs caused by having `:` in a symbol to be the fault of the one naming the symbol~ | 2017-11-28T18:40:39.000257 | Margaret |
clojurians | clojure | ```Symbols beginning or ending with ':' are reserved by Clojure. A symbol can contain one or more non-repeating ':'s.``` ugh - never mind then - that seems like a terrible choice to me, but it’s allowed | 2017-11-28T18:42:29.000205 | Margaret |
clojurians | clojure | well, time and again, in these kind of discussions a distinction has been made between legal symbols and readable symbols | 2017-11-28T18:52:50.000146 | Rebeca |
clojurians | clojure | right, but those docs seem to say that a single : in a symbol is readable | 2017-11-28T18:57:58.000167 | Margaret |
clojurians | clojure | (and also legal) | 2017-11-28T18:58:07.000070 | Margaret |
clojurians | clojure | ```(ins)user=> ,(def foo:bar 1)
#'user/foo:bar
(ins)user=> foo:bar
1
(ins)user=> {::a foo:bar}
#:user{:a 1}``` | 2017-11-28T19:02:09.000113 | Margaret |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.