This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-11
Channels
- # announcements (2)
- # babashka (27)
- # beginners (99)
- # biff (16)
- # calva (15)
- # clj-kondo (6)
- # clj-on-windows (38)
- # clojure (54)
- # clojure-austin (1)
- # clojure-europe (30)
- # clojure-france (4)
- # clojure-nl (1)
- # clojure-norway (43)
- # clojure-spec (10)
- # conjure (28)
- # core-async (4)
- # cursive (7)
- # figwheel-main (1)
- # graphql (9)
- # gratitude (3)
- # honeysql (9)
- # introduce-yourself (1)
- # jobs (1)
- # joyride (128)
- # lambdaisland (2)
- # malli (8)
- # membrane (12)
- # nbb (5)
- # off-topic (1)
- # polylith (11)
- # re-frame (9)
- # reitit (1)
- # remote-jobs (5)
- # sci (15)
- # shadow-cljs (50)
- # tools-deps (2)
- # xtdb (12)
Is writing server log files as Clojure data structures a common practice in production? I'm curious about approaches like what https://github.com/BrunoBonacci/mulog does.
In cloud environments is more common to ship logs/events/traces to cetralised logging systems. And mulog publishers can help you with that.
writing local files on ephemeral machines (like the cloud machines) is a recipe for disaster!
Thanks, @U0LCHMJTA. I think I mis-phrased my question. What I mean to ask is whether it is common practice to feed Clojure data structures to production logging systems, but now I see that several of the mulog publishers will translate into JSON before sending it off. That makes it more clear. Thank you. I'll find some time to watch the full video soon.
ahhh i see. the format depends on the target systems. most systems have JSON REST API. some (like Prometheus) have custom/proprietary formats. Others are binary. EDN capable systems are rare.
Is there an idiom for (or foo 42)
except the default value 42
is only chosen when foo
is nil
and not when foo
is false
?
Another fun alternative ( not idiomatic 😅):
(some some? [foo 42])
If you really hate it, then you can write a macro.
But using if
is a proper solution here.
depending on context, fnil
may also be useful for nil-patching a function call
Isn't str/re-quote-replacement
supposed to escape dots (or rather, the underlying Java lib)?
user=> (re-matches (re-pattern (clojure.string/re-quote-replacement "..")) "xx")
"xx"
re-quote-replacement is for making a replacement string to be used with replace
, not to make an re. (see https://docs.oracle.com/javase/8/docs/api/java/util/regex/Matcher.html#appendReplacement-java.lang.StringBuffer-java.lang.String-)
user=> (clojure.string/replace "xx" (re-pattern (clojure.string/re-quote-replacement "..")) "ff")
"ff"
why are you using re-pattern?
the last arg is not an re
http://clojure.github.io/clojure/clojure.string-api.html#clojure.string/replace
sorry, I'm mismatching the args, but again, you should be using re-quote-replacement for the last arg
(clojure.string/replace "xx" (re-pattern "..") (clojure.string/re-quote-replacement "ff"))
How can I quickly and reliably get an io/output-stream
at some path if the referenced path doesn’t already exist? Creating an output-stream for a file on-demand works fine if there are no subdirectories, but I need to also create the file when given a path containing subdirectories, e.g path/to/file.ext
.
I’m sure there is some quick way to do this, saving me the trouble of writing the code myself…
io/make-parents
+ output-stream
@alexmiller Thank you, Alex! Exactly what I was looking for.
Hi all: is there any way, given a namespace object, to return the resource (if there is one), which was compiled to produce the namespace? You can check the vars in the namespace object to see if they have a :file
attribute in the metadata, but not all the namespaces that are compiled from files will have vars. Some might be computed for side effects, but still have files.
( "clojure/core/match.clj")
#object[java.net.URL
"0x4a2fa566"
"jar:file:/Users/dan/.m2/repository/org/clojure/core.match/1.0.0/core.match-1.0.0.jar!/clojure/core/match.clj"]
you can play around with this notion. Note that it is slightly different than the namespace name.
Gotcha. I was hoping to avoid having to think through the edge cases, since presumably Clojure is already doing this to create the namespace. Is it really as simple as just swapping out the .
for /
and and the
-` for _
, and then checking for both .clj
and .cljc
files?
namespaces are not tied to files, you can have multiple namespaces declared in one file, or a namespace spread thru multiple files (like clojure.pprint)
oh, missed that sorry
But you’re right. Lots of ways this could work poorly. But in general, will probably work quite a bit
clojure.pprint is one case of that
That is a good point about multiple files. Luckily, in my particular case as long as I can map consistently to the root resource (if there is one), that is sufficient for my purposes.
OK not sure why I’m getting an ArityException on this custom protocol:
(import '[org.apache.jena.graph Node NodeFactory Triple])
(defprotocol Predicate
(-create-triple
[pred subj obj])
(-add-triple!
[pred subj obj triples]
[pred subj obj triples idx]))
(extend-protocol Predicate
Node
(-create-triple [p s o]
(Triple. s p o))
(-add-triple! [p s o coll]
(.addTriple coll ^Triple (-create-triple p s o)))
(-add-triple! [p s o coll idx]
(.addTriple coll idx ^Triple (-create-triple p s o))))
(let [triple-block (ElementPathBlock.)]
(-add-triple! (NodeFactory/createVariable "y")
(NodeFactory/createVariable "x")
(NodeFactory/createVariable "z")
triple-block))
; Execution error (ArityException) at com.yetanalytics.flint-jena.triple/eval10084$fn$G (triple.clj:14).
; Wrong number of args (4) passed to: com.yetanalytics.flint-jena.triple/eval12288/fn--12291
The 5-arity version works, but not the 4-arity versionI am passing a this
argument though. NodeFactory/createVariable
returns a Node
instance, which serves as the this
arg for both the 4- and 5-arity -add-triple!
functions.
I wonder if this is an issue with extend-protocol
. If I switch the order the two -add-triple!
impls under Node
, then it’s the 5-arity version that throws the exception
% clj
Clojure 1.11.1
user=> (defprotocol Predicate
(-create-triple
[pred subj obj])
(-add-triple!
[pred subj obj triples]
[pred subj obj triples idx]))
Predicate
user=> (doc -add-triple!)
-------------------------
user/-add-triple!
([pred subj obj triples] [pred subj obj triples idx])
nil
user=>
Aha! Figured it out:
(extend-protocol Predicate
Node
(-create-triple [p s o]
(Triple. s p o))
(-add-triple!
([p s o coll]
(.addTriple coll ^Triple (-create-triple p s o)))
([p s o coll idx]
(.addTriple coll idx ^Triple (-create-triple p s o))))
The issue is that the extend-protocol
multiple-arity syntax is slightly different from, say, the defrecord
syntax