workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
clojurians | clojure | I totally read over that, oops | 2017-11-08T12:53:28.000297 | Georgianne |
clojurians | clojure | that makes sense. Thanks! | 2017-11-08T12:53:33.000048 | Georgianne |
clojurians | clojure | it only explicitly documents the return-value of the `thrown?` check, I guess it’s implied that `thrown-with-msg?` would similarly return e | 2017-11-08T12:55:02.000713 | Margaret |
clojurians | clojure | Does anyone have an idea what could be wrong here?
```
(defn testex []
(go
(let [response (try (<! (http/get "<http://localhost:3000/sim/error>" {:with-credentials? false}))
(catch :default e
(println "error" e)))]
(println response))))
```
The URL returns HTTP 500 with content-type application/json but not a JSON body, so http/get throws a parse error, but I can't figure out why I can't catch it. I tried putting the `try` everywhere. | 2017-11-08T13:50:18.000375 | Chang |
clojurians | clojure | you can’t catch it because channel ops are lifted into core.async’s state machine | 2017-11-08T13:50:52.000744 | Margaret |
clojurians | clojure | so the fact that http/get returns a channel means that you can’t catch its error - in order to handle that error you need to use the facilities your http library defines, and if they define none the library is broken | 2017-11-08T13:51:36.000377 | Margaret |
clojurians | clojure | normal clj-http at least takes a `:throw-exceptions` arg you can set to false - I don’t know what library `http` is but with any luck they accept that arg and return the error response instead of throwing an error(?) - I have no idea why that wouldn’t be the default in an async lib frankly | 2017-11-08T13:53:40.000255 | Margaret |
clojurians | clojure | I use this one: <https://github.com/r0man/cljs-http> . Are there alternatives out there that also use core.async? | 2017-11-08T13:54:36.000706 | Chang |
clojurians | clojure | so this means that any code that returns a channel should never throw an error? | 2017-11-08T13:57:16.000444 | Chang |
clojurians | clojure | :default likely doesn't work correctly inside clojurescript core.async go blocks anyway | 2017-11-08T13:57:29.000436 | Rebeca |
clojurians | clojure | asynchronous code shouldn't throw errors. who's gunna catch it? | 2017-11-08T13:57:43.000094 | Aldo |
clojurians | clojure | not just core.async | 2017-11-08T13:57:46.000119 | Aldo |
clojurians | clojure | <https://dev.clojure.org/jira/browse/ASYNC-42> | 2017-11-08T13:58:01.000550 | Rebeca |
clojurians | clojure | <@Chang> it can throw an error if its non recoverable, what would be the point? but yeah, it shouldn’t throw exceptions because there’s no reasonable block of code that can catch it | 2017-11-08T13:58:07.000098 | Margaret |
clojurians | clojure | anyway looking at that code it doesn't seem like it would throw exceptions to me, it looks like it returns some sort of structured error | 2017-11-08T13:58:37.000367 | Aldo |
clojurians | clojure | <@Chang> looking at that lib it isn’t the one throwing, yeah | 2017-11-08T13:59:22.000129 | Margaret |
clojurians | clojure | but really, you can just use xhr via interop, and use core.async inside the callback | 2017-11-08T13:59:37.000500 | Margaret |
clojurians | clojure | that way you can attach your own error handler inside the callback | 2017-11-08T13:59:47.000333 | Margaret |
clojurians | clojure | wrapper libs are severely overrated | 2017-11-08T13:59:57.000771 | Margaret |
clojurians | clojure | <@Margaret>
```
ioc_helpers.cljs?rel=1509880107319:42 Uncaught SyntaxError: Unexpected token S in JSON at position 0
at JSON.parse (<anonymous>)
at cljs_http$util$json_decode (util.cljs?rel=1509894674732:63)
at core.cljs:4829
at Function.cljs.core.update_in.cljs$core$IFn$_invoke$arity$3 (core.cljs:4829)
at cljs$core$update_in (core.cljs:4820)
at cljs_http$client$decode_body (client.cljs?rel=1509894676467:83)
at Function.<anonymous> (client.cljs?rel=1509894676467:181)
at Function.cljs.core.apply.cljs$core$IFn$_invoke$arity$2 (core.cljs:3685)
at cljs$core$apply (core.cljs:3676)
at async.cljs?rel=1509880110795:712
``` | 2017-11-08T14:00:17.000199 | Chang |
clojurians | clojure | right, so your server is giving your garbage that isn’t json, and cljs-http isn’t set up to catch that for you | 2017-11-08T14:00:47.000107 | Margaret |
clojurians | clojure | you need to either replace wrap-json with something that handles the error nicely, or just use xhr and js/JSON yourself directly | 2017-11-08T14:01:09.000604 | Margaret |
clojurians | clojure | my bet is that in the long term that last option is the least trouble | 2017-11-08T14:01:22.000259 | Margaret |
clojurians | clojure | well, I was using JulianBirch/cljs-ajax before, which is ok, but I wanted a solution where my logic in not split in event handlers | 2017-11-08T14:04:13.000463 | Chang |
clojurians | clojure | for simple stuff there should be no problem, but as soon as you have something more complex, like several ajax requests in sequence it gets messy | 2017-11-08T14:05:14.000368 | Chang |
clojurians | clojure | right, you can use core.async in your callback - then you’re in clojure land | 2017-11-08T14:09:31.000183 | Margaret |
clojurians | clojure | regarding "who should catch the error", my answer would be "the code inside go". core.async gives you the illusion to have sequential code when its actually asynchronous, right? so that is where errors should handled as well. ironically throwing an exception/error is actually a break in a sequential code. i don't know how it works internally, i just recently learned that they are actually not the same as continuations, so it may not be easy or possible, but that question definitely has an answer | 2017-11-08T14:11:20.000145 | Chang |
clojurians | clojure | Do people prefer to use for list comprehensions or filter and map? | 2017-11-08T14:11:36.000269 | Alix |
clojurians | clojure | <@Chang> but that’s impossible - your go block can’t see errors inside another go block, and that’s what is happening in your code when you call http/get | 2017-11-08T14:12:47.000029 | Margaret |
clojurians | clojure | this is a hazard of using library code that creates go blocks you can’t control | 2017-11-08T14:13:31.000488 | Margaret |
clojurians | clojure | <@Margaret> it may be technically impossible (though I'm not so sure about that), but not logically. my point is that asynchronous code should have a generic way of dealing with errors, like sequential code has. blaming the library for not following a convention and not having a way to deal with that is not good :slightly_smiling_face: | 2017-11-08T14:19:46.000767 | Chang |
clojurians | clojure | OK - you would need to re-implement core.async to implement this | 2017-11-08T14:20:42.000184 | Margaret |
clojurians | clojure | it’s a core structural problem, not a superficial oversight | 2017-11-08T14:20:56.000404 | Margaret |
clojurians | clojure | hmm, i'm going to have to get to know core.async better to understand that. I come from JS promises, where errors are part of the "promise system", i.e. when you have a promise chain, and one of the steps throws an error it is caught by the "promise system" and the closest error handler (sort of like a catch) is executed. granted it's not perfect, for example errors while creating the promise chain are not caught. | 2017-11-08T14:30:15.000064 | Chang |
clojurians | clojure | i'm going to follow your recommendation and switch back to JulianBirch/cljs-ajax | 2017-11-08T14:31:24.000635 | Chang |
clojurians | clojure | this might be a better discussion for <#C05423W6H|core-async> - and perhaps I’m wrong and there’s a way to put in a more generic exception handler for go blocks- but if that existed I’d think we would have seen it in action already | 2017-11-08T14:31:36.000256 | Margaret |
clojurians | clojure | <@Margaret> thank you | 2017-11-08T14:32:07.000553 | Chang |
clojurians | clojure | to be clear, I recommended using xhr and JSON via interop, but if that works and is easier that’s cool too :smile: | 2017-11-08T14:32:17.000729 | Margaret |
clojurians | clojure | why would you favour xhr vs a cljs library? | 2017-11-08T14:32:58.000058 | Chang |
clojurians | clojure | <@Alix> I would choose what looks best aesthetically (by which I mean what code is more understandable), but I guess performance may also matter in some cases. why do you ask? | 2017-11-08T14:37:56.000090 | Chang |
clojurians | clojure | <@Chang> because wrapper libs are limiting, and interop is strightforward | 2017-11-08T14:39:33.000727 | Margaret |
clojurians | clojure | using the js lib directly will be the most flexible option, and least likely to get you stuck | 2017-11-08T14:39:58.000769 | Margaret |
clojurians | clojure | <@Chang> cool, I am learning how to write better code | 2017-11-08T14:41:52.000492 | Alix |
clojurians | clojure | Anyone know of a good HTML extracting library? I want something that can use CSS or xpath selectors that can be represented in text so that I can store them in a config somewhere. Tried hickory and it works but it’s not geared toward text based parsing instructions. | 2017-11-08T19:12:04.000035 | Merri |
clojurians | clojure | this is what enlive does <https://github.com/cgrand/enlive> | 2017-11-08T19:13:23.000231 | Margaret |
clojurians | clojure | or - at least - I have done this with enlive before | 2017-11-08T19:13:45.000115 | Margaret |
clojurians | clojure | neat. I always thought it was a templating library. thanks! | 2017-11-08T19:14:04.000218 | Merri |
clojurians | clojure | yeah, it templates too, but it can also break down html input and search it via selectors | 2017-11-08T19:14:28.000005 | Margaret |
clojurians | clojure | I've used it alot but have never templated with it | 2017-11-08T19:14:51.000230 | Margaret |
clojurians | clojure | looks like I could maybe store the config in edn or something. cool. | 2017-11-08T19:15:25.000094 | Merri |
clojurians | clojure | ,1 | 2017-11-08T22:12:52.000017 | Charity |
clojurians | clojure | A question about selecting Clojure libraries:
Anyone know, offhand, of a site that will let you search a Clojure project by the other projects (with public dependency information eg on github) that have it as a dependency? I'd find this useful when understanding if and how certain libraries are being used. | 2017-11-09T02:43:04.000321 | Harriet |
clojurians | clojure | I feel sure this thing / project does or did exist, but I've forgotten where to find it. | 2017-11-09T02:54:28.000260 | Harriet |
clojurians | clojure | <@Harriet> check out <https://crossclj.info/> | 2017-11-09T03:04:15.000372 | Austin |
clojurians | clojure | Hi Guys,
I've tried to test pmap functionality and came across a weird (to me) behaviour.
It would be nice if someone could tell me where am I wrong, or how does it make sence:
For my understanding pmap goal is to run a function in parallel over a collection, limiting parallelism.
From pmap code I underatand that the desired parallelism level is 2+num-of-cpus
In practice i see a different behaviour:
```(defn- f1 [delay-num]
(info "delay #" delay-num "started, sleeping")
(Thread/sleep (* 1000 5))
(info "delay #" delay-num "finished")
delay-num)
(defn run []
(let [delays (range 21)
results (pmap f1 delays)]
(info "num of cpus = " (.. Runtime getRuntime availableProcessors))
(info "total is" (reduce + results))))
```
This shows all 20 delays running in parallel
(I have 4 CPUs and running with clojure 1.8)
Trying to understand it I came up that applying the seq on fs is to "blame".
What do u say? | 2017-11-09T03:35:09.000183 | Armida |
clojurians | clojure | Not sure if it has been asked before - I can't find it googling for it - but with Java9 and the modularization of the JDK, I'm wondering if there's a kind of 'minimal JDK for clojure'? The reason for asking is: on small devices, RAM is still limited, and starting a few full blown JVM's takes quite some unnecessary baggage (CORBA, Swing, ...). It would be nice to have a JDK which contains the necessary modules, but not more, that clojure needs to run. I guess it could save up to maybe 30-40MB per JVM. Running 4-5 clojure apps on a 1-2 GB RAM device, well, it certainly makes a difference. | 2017-11-09T03:35:44.000159 | Darci |
clojurians | clojure | I've never actually used it: but have you looked into things like Wildfly? It's supposed to let you multiple applications in one JVM process. It *might* be able to help you *now* instead of waiting for the devs to do it. | 2017-11-09T03:41:37.000374 | Janette |
clojurians | clojure | Thanks! That's the one. | 2017-11-09T03:44:39.000140 | Harriet |
clojurians | clojure | <@Armida> I guess this has something to do with chunked seqs. `map` et al process sequences in chunks of 32 elements.
And this is indeed what I observe | 2017-11-09T04:08:02.000148 | Terra |
clojurians | clojure | ```
(defn- f1 [delay-num]
(Thread/sleep (+ 100 (rand-int 1000)))
(println (java.util.Date.) "delay #" delay-num "started")
(Thread/sleep (* 1000 5))
(println (java.util.Date.) "delay #" delay-num "finished")
delay-num)
(defn run []
(let [delays (range 41)
results (pmap f1 delays)]
(println "num of cpus = " (.. Runtime getRuntime availableProcessors))
(println "total is" (reduce + results))))
(run)
#inst "2017-11-09T09:06:30.493-00:00" delay # 1 started
#inst "2017-11-09T09:06:30.498-00:00" delay # 2 started
#inst "2017-11-09T09:06:30.559-00:00" delay # 13 started
.....
``` | 2017-11-09T04:09:20.000241 | Terra |
clojurians | clojure | cool - thanx! wasn't aware of that at all.
so it seems that num-of-cpus calculation is redundant right? unless you have more than 30 cpus. | 2017-11-09T04:25:07.000386 | Armida |
clojurians | clojure | correct, if you're pmapping over a chunked seq | 2017-11-09T04:52:50.000029 | Kareen |
clojurians | clojure | OTOH you can dechunk it and get back the expected n+2 behaviour | 2017-11-09T04:53:14.000420 | Kareen |
clojurians | clojure | or if your sequence isn't chunked, that will be the case too | 2017-11-09T04:53:26.000264 | Kareen |
clojurians | clojure | understood. thanx a lot! | 2017-11-09T05:58:37.000163 | Armida |
clojurians | clojure | <@Darci> the JVM already runtime loads classes into memory as you use them. If they end up in RAM that's because something accessed them at runtime. The main RAM killer with Clojure in particular is the assumption that RAM is cheap and throughput is more important, which informs the design of the collections and the way the core functions use those collections. | 2017-11-09T06:41:00.000357 | Margaret |
clojurians | clojure | <@Janette> Yeah... I'm not particularly fond of application servers. I can't talk for all of them, but they still have a hard time if one of the applications is stopped unexpectedly (even in clojure, this happens :slightly_smiling_face: ). Many of them seem to have quite some issues with memory leaks as well. They're not real multi-tenant... I'm still hoping some day, there will be a real multi-tenant JDK.
<@Margaret> allright... I will check it. In my understanding - and seeing how much RAM 'hallo world' seems to use - the JDK loads the classes of the applications dynamically, but not the JDK itself. I may be completely wrong, though :slightly_smiling_face:. | 2017-11-09T07:01:01.000112 | Darci |
clojurians | clojure | Why even use a JDK if not compiling Java code? Clojure doesn't need one. you can just use a JVM. | 2017-11-09T07:02:01.000453 | Margaret |
clojurians | clojure | right... misphrased my question :slightly_smiling_face: | 2017-11-09T07:02:24.000216 | Darci |
clojurians | clojure | Being able to modularize and customize your own JVM, is there minimal clojure-JVM? - oh, I seem to answer my own question: clojure doesn't need any special JVM, so just JDK9 base (and maybe some other modules), be be ok. Could work.
However, without aot, would an an optimized JVM (which can compile clojure on the fly) make sense? | 2017-11-09T07:04:25.000219 | Darci |
clojurians | clojure | Clojure can't run without the compiler anyway can it? | 2017-11-09T07:05:50.000034 | Margaret |
clojurians | clojure | right. | 2017-11-09T07:06:36.000151 | Darci |
clojurians | clojure | my hello.java has 21 megs resident (I threw a Thread.sleep so I would have enough time to find it in htop) | 2017-11-09T07:10:23.000393 | Margaret |
clojurians | clojure | that's a lot more than I would see in C, but it's a lot less than clojure.core takes up | 2017-11-09T07:10:47.000262 | Margaret |
clojurians | clojure | for reference ```class Main {
public static void main (String[] argv)
throws InterruptedException {
Thread.sleep(100000);
}
}
``` | 2017-11-09T07:11:42.000062 | Margaret |
clojurians | clojure | Right... so, I'll check how much it would take for clojure - later. | 2017-11-09T07:12:29.000145 | Darci |
clojurians | clojure | my clojure 1.9.0-RC1 with no other deps is 83 megs resident before I do any require calls | 2017-11-09T07:14:07.000264 | Margaret |
clojurians | clojure | pulling in core.async brings it up to 298 megs | 2017-11-09T07:14:42.000091 | Margaret |
clojurians | clojure | this is without lein, boot, or any other tooling | 2017-11-09T07:15:04.000178 | Margaret |
clojurians | clojure | OK, so it's pretty clear what the memory is necessary for | 2017-11-09T07:15:43.000269 | Darci |
clojurians | clojure | it's not the JVM :slightly_smiling_face:. Meaning, no need to start fiddling with it :slightly_smiling_face: | 2017-11-09T07:16:08.000010 | Darci |
clojurians | clojure | this is on ```$ java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
``` | 2017-11-09T07:16:26.000302 | Margaret |
clojurians | clojure | yeah - java isn't the primary thing driving memory usage here - I'm sure java's design and optimization criteria play a part, but it's dwarfed by the memory used by clojure itself to define data structures and functions | 2017-11-09T07:17:26.000344 | Margaret |
clojurians | clojure | FYI: you can get some info about memory usage with `(bean (ManagementFactory/getMemoryMXBean))` | 2017-11-09T07:18:04.000132 | Randee |
clojurians | clojure | ok, nice, thx a lot. This will do for now :slightly_smiling_face:. I guess I'll just have to see if I can work it out to use clojure on small devices. | 2017-11-09T07:19:49.000258 | Darci |
clojurians | clojure | Clojure's design assumes RAM is cheap (Rich Hickey has talked about this when talking about Clojure's design assumptions) | 2017-11-09T07:21:58.000124 | Margaret |
clojurians | clojure | yeah, I know... but I just seem to have a hard time to not using clojure these days. | 2017-11-09T07:22:50.000312 | Darci |
clojurians | clojure | there are other functional languages (some of them even in the lisp family) that don't make that assumption | 2017-11-09T07:23:04.000006 | Margaret |
clojurians | clojure | in my experience OCaml is really good about runtime memory usage if you stick to the core language as much as possible | 2017-11-09T07:23:41.000246 | Margaret |
clojurians | clojure | Or I'll may have to see for another lisp... or maybe Erlang or OCaml. | 2017-11-09T07:23:51.000330 | Darci |
clojurians | clojure | somewhat related: <https://ferret-lang.org/> | 2017-11-09T07:24:06.000117 | Katharyn |
clojurians | clojure | nice... looks pretty cool as well. | 2017-11-09T07:25:13.000070 | Darci |
clojurians | clojure | I use OCaml for a project on the raspberry pi, I could compile OCaml to machine code ~100 times then run it, in the time it takes Clojure to start up on the pi | 2017-11-09T07:26:06.000207 | Margaret |
clojurians | clojure | (rough rough estimate) | 2017-11-09T07:26:19.000173 | Margaret |
clojurians | clojure | :slightly_smiling_face: | 2017-11-09T07:26:19.000433 | Darci |
clojurians | clojure | <@Darci> you could also look into clojerl or LFE | 2017-11-09T07:34:46.000102 | Evan |
clojurians | clojure | <@Annabelle> you have experience with them (they seem to be experimental, whatever that really means) | 2017-11-09T07:36:46.000342 | Darci |
clojurians | clojure | no experience, sorry | 2017-11-09T07:37:16.000097 | Evan |
clojurians | clojure | np... again too many things to try out. | 2017-11-09T07:38:40.000178 | Darci |
clojurians | clojure | Is it possible to save maps with namespaced keys to mongo ? | 2017-11-09T07:39:22.000131 | Celina |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.