This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-03
Channels
- # aleph (2)
- # announcements (13)
- # babashka (7)
- # beginners (36)
- # calva (26)
- # cider (11)
- # circleci (13)
- # clj-kondo (15)
- # clojure (105)
- # clojure-europe (79)
- # clojure-nl (3)
- # clojure-uk (6)
- # clojurescript (17)
- # conjure (4)
- # core-logic (2)
- # cursive (10)
- # data-science (5)
- # datalevin (11)
- # datalog (14)
- # eastwood (6)
- # emacs (2)
- # figwheel-main (1)
- # fulcro (34)
- # google-cloud (1)
- # graphql (3)
- # introduce-yourself (7)
- # jobs (1)
- # leiningen (17)
- # lsp (46)
- # malli (2)
- # minecraft (3)
- # missionary (19)
- # off-topic (31)
- # other-languages (49)
- # polylith (2)
- # portal (5)
- # practicalli (1)
- # quil (77)
- # releases (1)
- # remote-jobs (1)
what is a transducer way to say some
? What I'm after is finishing the transduction as soon as 1 element satisfies a pred
hi, using spec, is there some way to validate specs with OR?
(s/def :a/x int?)
(s/def ::A (s/keys :req-un [:a/x]))
(s/def :b/y string?)
(s/def ::B (s/keys :req-un [:b/y]))
(s/explain (s/or ::A ::B) {:x 1})
=> {:x 1} - failed: (contains? % :y) at: [:user/A] spec: :user/B
while i'd expect it to succeed as :`:A` is valid?
what i'm missing here?
You have the wrong syntax for s/or
Each sub spec also has a keyword tag
So something like (s/or :a ::A :b ::B)
but doesn't :A include :a ?
as :A and :B are huge (each spec defined separately) - i'd want validate on some or some composition of
The :a and :b are labels for which branch of the or is matched, not references into the spec
I want to know the last seen shape of data as it flowed through a function. Something like... cider with a local copy of sample results saved when i run things... and a way to pull that info up
having a "last snapshot of the inputs to this function" by input-arg would be superhuman tooling
something like "cider cache"
where I can press a key combo and see the last time this function was run, what the inputs looked like and what the output was.
seems like that should be easy enough to cobble together ... here's my attempt:
(comment
(defn- priv [& args]
(throw (Exception. "test")))
(def calls (atom nil))
(defn instument-ns []
(->> (ns-interns *ns*)
vals
(remove #{#'instument-ns})
(map (fn [v] (alter-var-root v (fn [f] (if (fn? f)
(fn [& args]
(swap! calls assoc v {:args args})
(let [[r e] (try [(apply f args)] (catch Throwable t [nil t]))]
(if e
(swap! calls assoc-in [v :error] e)
(swap! calls assoc-in [v :result] r))
(if e
(throw e)
r)))
f)))))
dorun))
(instument-ns)
(priv :thing2)
(get @calls #'priv)
)
I guess that'd probably work without cider too ... ??Right right, reckon I have a huge project though with many files. And I want cached results for whatever has been run in any file... maybe even independently of runtime
(defn instument-ns []
(->> (all-ns)
(filter #(-> % ns-name name (.startsWith "user")))
(map ns-interns)
(mapcat vals)
(map (fn [v] (alter-var-root v (fn [f]
(if (fn? f)
(fn [& args]
(swap! calls assoc v {:args args})
(let [[r e] (try [(apply f args)] (catch Throwable t [nil t]))]
(if e
(swap! calls assoc-in [v :error] e)
(swap! calls assoc-in [v :result] r))
(if e
(throw e)
r)))
f)))))
dorun))
you could do it for all namespaces that start with a prefix? ...I tried sayyid quite a while ago, it seemed good, but I ended up not using it much ... I've not tried omni-trace ...
It would be cool to peg down a tool. How can I run the code you wrote?
Hey team, I’m having some trouble getting uncaught exceptions to log, in the following case:
Say I have a -main
function like this:
(defn -main []
(throw (Exception. "test"))
If I try to run it:
lein with-profile production run -m my-project.my-ns
I get something along the lines of this:
SLF4J: A number (104) of logging calls during the initialization phase have been intercepted and are
SLF4J: now being replayed. These are subject to the filtering rules of the underlying logging system.
SLF4J: See also
Syntax error compiling at (/tmp/form-init7632496378080193395.clj:1:73).
test!
Full report at:
/tmp/clojure-1115158083760869108.edn
Error encountered performing task 'run' with profile(s): 'production'
Suppressed exit
But the problem is, I think this kind of error is completely shutting the system down, and hence no logs are being sent to my logger.
I’m not quite sure how to make things work so that even in this case the logger gets a message. Thoughts much appreciated!(currently just wrapped the work in -main under a try catch, but would be curious to hear if there’s a way to avoid that)
-main is the entrypoint/start/of your javaprocess it wont handle any exception by default. Since an exception is mechanism to stop "normal execution flow" to indicate something "exceptional" has happen, -main cant know what to do with the exception other than stop the program. So if you want to catch and log any exception you should wrap your logic inside main with a try catch, and catch.
(defn -main [& args]
(try
(your-logic-or-service)
(catch Exception e
(logging-library-you-are-using/error e)
(throw e) )))
Notice I'm re-throwing the exception, in general, exception handling should handle the exception, i.e. stop the exception propagation, but here I wouldn't know want to do other than stopping the java process with and error.
Usually you would log the exception were it is handledthat's correct, main is the top of the stack, if the exception reached main with out being handled, there's no much left to do than stopping the process with an error
This makes sense. Thanks for the context @U487Z32UF!
(def data {"Leading zeros ids" "00121", "Test" "123", " test 1" "abc"})
(defn interpret-numbers
[data]
(update-vals
data
(fn [v]
(if (and (every? #(Character/isDigit %) v)
(or (= v "0")
(not (string/starts-with? v "00")))
(parse-long v)
v))))
using parse-long and update-vals from 1.11 - there are sorts of map-vals in multiple libraries and you saw Long/parseLong
is a good enough replacement for now
@emccue Sounds like @ps wants a ClojureScript solution, not Clojure. Or at least, both Clojure and ClojureScript.
Hey, How do I equality check a defrecord
with a hashmap
which both have the same values? Trying to write a test which compares the two but the defrecord
has a tagged literal