This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-08
Channels
- # announcements (2)
- # babashka (100)
- # beginners (25)
- # biff (7)
- # calva (13)
- # cider (24)
- # clj-kondo (39)
- # cljsrn (2)
- # clojure (22)
- # clojure-dev (13)
- # clojure-europe (12)
- # clojure-gamedev (3)
- # clojure-losangeles (2)
- # clojure-nl (1)
- # clojure-norway (3)
- # clojure-spec (11)
- # clojure-uk (2)
- # clojurescript (20)
- # core-async (8)
- # cursive (7)
- # data-science (2)
- # datomic (14)
- # emacs (6)
- # events (7)
- # fulcro (9)
- # honeysql (1)
- # kaocha (24)
- # lambdaisland (3)
- # leiningen (6)
- # lsp (30)
- # membrane (7)
- # missionary (10)
- # nbb (48)
- # nextjournal (13)
- # off-topic (6)
- # parinfer (4)
- # pathom (1)
- # polylith (1)
- # reagent (7)
- # rewrite-clj (6)
- # ring (11)
- # sci (7)
- # shadow-cljs (8)
- # sql (13)
Question about core.cache and errors thrown by functions which are cached. Details in thread
demo=> (defn is-odd? [x]
(println "computing for " x)
(if (odd? x) true (throw (ex-info "boom" {}))))
#'demo/is-odd?
demo=> (def modd (memoize/ttl is-odd? :ttl/threshold 30000))
#'demo/modd
demo=> (modd 3)
computing for 3
true
demo=> (modd 5)
computing for 5
true
demo=> (memoize/snapshot modd)
{[3] true, [5] true}
demo=> (modd 2)
computing for 2
Execution error (ExceptionInfo) at demo/is-odd? (REPL:181).
boom
demo=> (memoize/snapshot modd) ;; this blows up with the error from above
computing for 2
Execution error (ExceptionInfo) at demo/is-odd? (REPL:181).
boom
define a function that can throw an error (in the real case network access for http requests). I’m confused why (memoize/snapshot modd)
would throw here. I dont see any documentation about what the defined behavior is for errors
It seems to not cache when the underlying function throws an error, but i’m surprised that the snapshot also throws an error
https://github.com/clojure/core.memoize/blob/master/src/main/clojure/clojure/core/memoize.clj#L121-L129 just goes through and reads the delays, if a delay threw an exception when it ran, it will throw it everytime it is deref'ed
This feels inconsistent to me. If i repeatedly call (modd 2)
I get each time the message “recomputing for 2” and it treats it as not cached. But if I look at the cache it treats it as if it is cached (and prevents me from seeing the actual cache)
Perhaps i’m looking at it wrong but it does seem to be both cached and not cached (and in the wrong direction for my purposes on each side)
but it is true that the cache contains an entry for whatever throws the exception, the entry just throws an exception when you try and read it
fair enough. thanks @U0NCTKEV8
Yeah i’m looking at error handling with a ttl cache in general. We put a token check behind a ttl cache and it floods our logs with errors when there’s no network access. Ideally I could cache an error for a different time than the successful request but that doesn’t seem to be an option. And in the case of errors it reverts back to un-cached so quite a bit of unnecessary work
Hey! I'm trying to use atom but for some reason I can't get it working when passing it to other functions. For example, the expected output of this is 10 but it outputs 0. Am I doing something wrong?
(defn f [at val]
(swap! at (partial + val)))
(let [at (atom 0)
something (map #(f at %) (range 5))]
(println @at))
map
is lazy. try run!
instead
or mapv
or wrap the call to map with doall
if you don't care about the return value, run!
should be preferred. if you do care about the return value, then I would recommend mapv
@U7RJTCH6J thank you for pointing that out! is there any way to do something similar to pmap, but so that it resolves only after everything from the collection is consumed?