Fork me on GitHub
#clojure
<
2016-01-17
>
rm03:01:26

rcanepa: you don't want to do this. What if your database connection failed? Or something else happened? You will never know about it

mpenet09:01:14

you can send the exception somewhere (logging/channel etc). "future" is not problem free, but this one is something you can handle yourself

mpenet09:01:51

also a good thing to do, especially with core.async, is to use Thread/setDefaultUncaughtExceptionHandler to show/log what is breaking in other threads

mpenet09:01:14

just be aware that the threadpool where "future" runs is unbounded tho...

jaen09:01:15

Or maybe use a custom threadpool and pass it functions to execute? If you're never going to use the result it seems more appropriate than a future. https://github.com/ztellman/dirigiste https://github.com/TheClimateCorporation/claypoole seem like sensible libraries for custom threadpools. Clojure features page even mentions that Clojure functions are java.util.concurrent.Callable so you can use them with Java Executors if you don't feel like adding another dependency.

sveri10:01:09

Hi, I have a clojure source file, that I wont to load, change and save. loading and saving is ok with spit and slurp. But how would I change the content. I want to add something to the ns declaration and to a function (so inside existing declarations).

jaen10:01:17

Since it's-just-data maybe something like https://github.com/nathanmarz/specter would be helpful?

sveri10:01:49

Yea, specter, true. I give it a try

sveri10:01:38

Hm, read-string only reads the first datastructure

sveri10:01:52

which is the ns declaration

sveri10:01:25

@darwin: Thanks, I try that too simple_smile

mpenet11:01:03

@jaen yeah custom threadpool is the way to go. Writting a tiny future fn that takes a pool is a couple of lines.

jrychter11:01:31

Curious why clojure.walk/stringify-keys drops namespaces from keys — is this intentional?

(walk/keywordize-keys (walk/stringify-keys {:example-namespace/example-key 1})) => {:example-key 1}
I expected to get this instead:
(walk/keywordize-keys (stringify-keys-preserving-ns {:example-namespace/example-key 1})) => {:example-namespace/example-key 1}

rcanepa12:01:34

@mpenet @jaen thanks… I will check the custom threadpool option.

agile_geek12:01:02

@jrychter name on keyword does same so maybe it just calls that?

jrychter12:01:27

@agile_geek: yes, it does call that. But I'm surprised it doesn't use both namespace and name. This causes obscure problems, because some software expects that the stringify-keys operation is invertible, which it isn't.

pesterhazy19:01:16

Is my assumption correct that if you read a resource in a repl, from the resources path, it will be cached and not re-read from disk until you restart the repl?

mheld19:01:16

how would I dispatch different actions based on argument type -> (do-thing :keyword arg1) has a different method body than (do-thing “string” arg1)

mheld19:01:38

would that be a defmulti thing?

mheld19:01:03

and/or should I be using schema for this?

pesterhazy19:01:55

you could use protocols for that

hans19:01:57

@pesterhazy: i think resource lookup is cached, but content itself is not.

hans19:01:41

@pesterhazy: not even lookup is cached.

mheld19:01:52

I mean, I really just want to write a (url-for {keyword | String} args) thing that knows what to do

mheld19:01:25

protocols seem kind of overkill for this

hans19:01:43

@mheld: defmulti is fine for that kind of thing.

pesterhazy19:01:53

@hans, I'll have to try it out. I've encountered problems a couple of times where resources weren't reread until a repl was restarted, or that's what I thought

mheld19:01:07

does keyword have a type?

hans19:01:33

@pesterhazy: i've seen similar things, but i guess someone with more knowledge needs to answer it. contents itself is surely not cached.

pesterhazy19:01:36

@hans, what did you mean with "lookup is cached", as opposed to "content is cached"?

hans19:01:46

@pesterhazy: i have experienced similar strange behavior with resources not found when i've added them at run time, but i just tried on the repl and it works well, i.e. i can add a resource that i've previously not seen with io/resource, and after i add it, io/resource sees it.

hans19:01:12

@pesterhazy: that is what i (wrongly) meant by "lookup is cached".

pesterhazy19:01:09

http://stackoverflow.com/a/4750325/239678 <-- this looks like there is some kind of caching

pesterhazy19:01:44

maybe you don't see it in the repl because you're creating a new connection each time

hans19:01:24

I never use getResourceAsStream simple_smile

meow20:01:15

does Keyword implement the IKEA protocol?

meow20:01:51

oops, OT 😇 😼