This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-06
Channels
- # aleph (1)
- # beginners (180)
- # calva (16)
- # cider (29)
- # clj-kondo (47)
- # cljsrn (5)
- # clojure (40)
- # clojure-dev (39)
- # clojure-europe (1)
- # clojure-italy (25)
- # clojure-nl (9)
- # clojure-russia (1)
- # clojure-spec (8)
- # clojure-uk (83)
- # clojurescript (54)
- # core-async (2)
- # datomic (20)
- # defnpodcast (7)
- # figwheel (6)
- # fulcro (6)
- # jobs (5)
- # joker (4)
- # kaocha (4)
- # luminus (4)
- # off-topic (8)
- # onyx (6)
- # pathom (14)
- # re-frame (28)
- # reagent (30)
- # remote-jobs (2)
- # shadow-cljs (88)
- # spacemacs (2)
- # specter (17)
- # sql (25)
- # tools-deps (78)
- # xtdb (1)
- # yada (2)
and I've defined this in src/data_readers.clj
: {jet/val clojure.core/str #_jet.data-readers/val}
but I'm getting:
$ echo '{:a "foo bar" :b 2}' | lein jet --from edn --to edn --query "(str :a #jet/val "/" :b)"
Exception in thread "main" java.lang.RuntimeException: No reader function for tag jet/val
I guess not, but are there also data readers that can read multiple forms, not only the one following it?
For cmd line usage it may be handy to do something like:
jet ... --query '
#jet/do :a
#jet/do :b
'
instead of writing:
jet ... --query '[
:a
:b
] ;; <- user might forget to close this
'
the vector already means a sequential query, so like implicit do, I might just wrap it
hello, how can i convert this java to clojure, in clojure i use ring, so i don’t have httpservletrequest,
in ring params i print is #object[java.io.ByteArrayInputStream 0x6b7b093d java.io.ByteArrayInputStream@6b7b093d]
worth checking out included/missing ring middlewares, as they should handle converting params, request body etc into clojure maps
@haiyuan.vinurs how is the data sent to your web service? POST? query params?
How do you guys handle contextual logging when using e.g manifold or core-async?
@jarvinenemil just a theory: you could use binding
to set contextual values for a specific call, and refer to the bound value in your logs
rough sketch:
(def ^:dynamic *user*)
(def ^:dynamic *task*)
(defn foo [uname]
(binding [*user* uname
*task* "foo"]
(bar uname))
ah ok, I've never really done "contextual logging" in Clojure before so it would be interesting to know how people do it when it comes to async-stuff.
In Java I've always just set the MDC
(thread local). Let's say you have a system with bank transactions and you want to have a trace-id for the transaction in the whole system.
there's something that clojure internals calls "binding conveyance", where the dynamic vars visible when launching the new thread / async context are imported into that new context when it's created
here's the magic
user=> (source clojure.core/binding-conveyor-fn)
(defn binding-conveyor-fn
{:private true
:added "1.3"}
[f]
(let [frame (clojure.lang.Var/cloneThreadBindingFrame)]
(fn
([]
(clojure.lang.Var/resetThreadBindingFrame frame)
(f))
([x]
(clojure.lang.Var/resetThreadBindingFrame frame)
(f x))
([x y]
(clojure.lang.Var/resetThreadBindingFrame frame)
(f x y))
([x y z]
(clojure.lang.Var/resetThreadBindingFrame frame)
(f x y z))
([x y z & args]
(clojure.lang.Var/resetThreadBindingFrame frame)
(apply f x y z args)))))
nil
beyond the multiple arities, it's very simple
(if you mean core.async, futures, manifold, or something else sanely designed for clojure usage that is)
also, dynamic bindings have the right semantics for contextual logging - they work as a stack, so when you escape the binding clause the values go back to their up-stack value