I would like to store a var (as a string) , then get it back as a var. Right now, I'm here.
(var-get (eval (read-string var-as-string)))
Is there a better/more idiomatic way to do this ?
This imply some security concerns.
I could probably check that the result of read-string
is a var in the expected namespace.
Do you see something something else ?You say "Var" but do you really mean "qualified symbol", e.g., foo.bar/quux
?
Yes, I hesitated on the case. 🙂 Thank you for the solution.
In general, if you find yourself reaching for eval
, there's probably a better solution 🙂
(requiring-resolve (symbol sym-as-sring))
would give you access to the value, including requiring/loading the namespace if necessary.
Hello, Clojure experts. I need some help figuring when Calva Paredit should drag sexpressions in pairs. (Currently you can only https://calva.io/paredit/#editing, but in places like maps and let
boxes it makes sense to drag by pairs. In this issue, there’s a gif showing my current dev version handling the key/value pairs in maps: https://github.com/BetterThanTomorrow/calva/issues/529 Hoping the reply thread to this post can collect me some ideas, wishes and “don’t forget about”. Thanks in advance! ❤️
clojure.tools.logging
(l/info "response\n" (pr-str response))
I use JUL and the issue is (.getMessage record)
is private String message;
.
I want to do (l/info {:foo 1} "response\n" (pr-str response))
or even use meta, but in log formatter I can’t read this, because I have this as string. Any way to pass different data, than string to formatter? Based on data I need to generate different data structure for log, which is structured to JSON.
So now I have {"severity":"INFO","logger-name":"api.logs.google-json-payload","message":"{:a 1} bar"}
, but I want to use this {:a 1}
to determine what structure I need to generate.
In some cases I need to add to JSON data like this, but I have to know when and I have to pass this data to formatter not as a string:
{"httpRequest" {"requestMethod" "POST"
"requestUrl" "<http://example.com/some/info?color=red>"
"status" 400
"remoteIp" "111.222.333.444"
"latency" "3.5s"}}
This is quite complex topic itself to talk about this on slack 🙂
For exception I could use ex-info
, but how to do it for normal logs?Hello , when i want to use Clojure from java, with java as "parent" application,what is the prefered way? uberjar clojure with lein and use it from Java maven project? or mix Clojure and Java into a maven project without lein use?
to me separate looks better but i dont know
@takis_ Probably the latter and then use the clojure java API https://clojure.github.io/clojure/javadoc/clojure/java/api/package-summary.html
I downloaded lein.bat but when I run it I get NullPointerException. ... Is it supposed to work? If so, how would you suggest I troubleshoot?
To clarify: The self-install reported it worked.
But a subsequent "lein" says NullPointerException.
Even "lein version" says NullPointerException.
I do not have a project.clj or any profiles on this machine yet.
If I cd to my home directory before I run "lein", then I get "ExceptionInInitializerError", blah blah, "Caused by NullPointerException" and all the stack frame start with either "java.base" or "clojure"
@phill, you have a specific #leiningen channel for leiningen based question. The #beginners section is there also for that kind of questions (,p. That said, it is suppose to work. Leiningen is ok, and I started there. But as a beginner, https://clojure.org/guides/deps_and_cli is maybe more "vanilla", and more easy to start with.
Thank you borkdude i am trying both now
and both are easy to use actually , at least for the simple things i do so far
has anyone tried to use re-matcher or re-groups recently? I can use things like re-find just fine but when I use re-matcher etc.. I get
#object[TypeError TypeError: Cannot read property 'call' of undefined]
@joeallen92 it looks like you are in CLJS? re-matcher
doesn't exist in CLJS
oooo ty