Fork me on GitHub

what is a transducer way to say some ? What I'm after is finishing the transduction as soon as 1 element satisfies a pred



👀 1
Ben Sless14:01:07

Another way is to do it with a different rf, take a look at the xforms library

Aviv Kotek14:01:45

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?

Alex Miller (Clojure team)15:01:54

You have the wrong syntax for s/or

Alex Miller (Clojure team)15:01:07

Each sub spec also has a keyword tag

Alex Miller (Clojure team)15:01:47

So something like (s/or :a ::A :b ::B)

Aviv Kotek15:01:10

but doesn't :A include :a ?

Aviv Kotek15:01:17

as :A and :B are huge (each spec defined separately) - i'd want validate on some or some composition of

Ben Sless15:01:37

Or takes a sequence of pairs of name and spec

Alex Miller (Clojure team)16:01:52

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.

Ben Sless19:01:22

Something like omni-trace or sayyid?

😮 1

seems like that should be easy enough to cobble together ... here's my attempt:


  (defn- priv [& args]
    (throw (Exception. "test")))

  (def calls (atom nil))

  (defn instument-ns []
    (->> (ns-interns *ns*)
         (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)


  (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)
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
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).

Full report at:
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]
      (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 handled


that'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 
    (fn [v]
      (if (and (every? #(Character/isDigit %) v)
               (or (= v "0")
                   (not (string/starts-with? v "00")))
        (parse-long 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


(just combining a bit of the other advice)


@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


You could always construct an instance of your record from the map with the automatically provided conversion function. Something like:

(defrecord Thing [a b])

  (= (->Thing 1 2) (map->Thing {:a 1 :b 2})) ;; => true 
Is that what you mean?


Yeh, That works 🙂 Thanks

👍 1