This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-13
Channels
- # adventofcode (51)
- # announcements (1)
- # babashka (7)
- # beginners (45)
- # berlin (2)
- # bristol-clojurians (1)
- # calva (38)
- # cider (2)
- # clara (25)
- # clj-kondo (2)
- # cljs-dev (25)
- # cljsrn (3)
- # clojure (112)
- # clojure-dev (6)
- # clojure-europe (5)
- # clojure-nl (1)
- # clojure-spec (15)
- # clojure-uk (93)
- # clojurescript (29)
- # clojutre (2)
- # core-async (78)
- # cursive (24)
- # datomic (29)
- # figwheel-main (1)
- # fulcro (50)
- # hugsql (1)
- # hyperfiddle (1)
- # luminus (1)
- # malli (26)
- # off-topic (40)
- # portkey (12)
- # reagent (22)
- # ring-swagger (1)
- # shadow-cljs (56)
- # spacemacs (24)
- # tools-deps (68)
anyone know how to write circularly dependent specs? E.g. (s/def ::foo ::bar) (s/def ::bar ::foo)
Circular dependencies work fine, as long as there is some case to bottom out to, but your example is just nonsensical
Trying to log in at http://clojure.atlassian.net and raise an issue. Getting "<my-e-mail> does not have access to Jira at http://clojure.atlassian.net" after logging in. What am I missing?
https://clojure.org/community/contributing#_reporting_problems_and_requesting_enhancements
To alleviate your shock a bit, it looks more like StackOverflow than a regular phpBB forum. 🙂
For the particular situation you mention, you can send a message to Alex Miller in the #clojure-dev channel here, and he will likely notice it fairly soon, and is the person who typically handles these things.
The issue at hand is indeed likely to be addressed at Alex. However, I'd be truly surprised if you see what's coming ... hold my 🍺 😉
I mean, Alex can handle the permissions issue you are experiencing, at least. Whether he has time to improve one of the Clojure contrib libraries that isn't already on his list of jobs, I have no idea 🙂
Hi! Given a tree data structure, what is the best way to drop all siblings after a particular node? Zippers? Prewalk? Thanks!
Enlive data for a DOM. Each node is a map with :children list
AFAIK, prewalk
doesn't inform you of your current position, nor it allows you to 'look' at nodes other than the current one
So zippers seem more apt
I can look at the children and change them though?
I think so. You can always make a new zipper out of an old one.
Take a look at https://clojure.github.io/clojure/clojure.zip-api.html , it has 'verbs' for the things you mention
(my experience is limited to rewrite-clj
, an analog but different API)
If you know indices of the relevant children in the path, you can just use update-in
and subvec
since vectors are associative containers from indices to values.
Note that subvec
does not copy the data - it just keeps a reference to it. So if you want to trim down a huge tree and throw the rest away, you probably want to turn each subvec
into a proper vector.
Thx folks! I try zippers, it's time to learn them finally!
Just make sure to not overcomplicate things just because you want to learn something. 🙂 There's no sense in calling (repeatedly n zip/down)
if the case is so simple that you can just use n
with update-in
directly.
It is not. I need to find a particular node in the tree - a <--more-->
, comment - and drop everything after it.
You might also try luck via the log4j route, see e.g. https://github.com/bwaldvogel/log4j-systemd-journal-appender Might be more 'effortless' in some ways, but making sense of all the parts (timbre -> timbre adapter -> java lib) might be painful
I would recommend switching to clojure.tools.logging and use an existing logback appender to route traffic to it:
<configuration>
<appender name="journal" class="org.gnieh.logback.SystemdJournalAppender" />
<root level="debug">
<appender-ref ref="journal" />
</root>
</configuration>
Deps:
;; Logging
[ch.qos.logback/logback-classic "1.2.3" :exclusions [org.slf4j/slf4j-api]]
[org.slf4j/slf4j-api "1.7.26"]
[org.slf4j/jul-to-slf4j "1.7.25"]
[org.slf4j/jcl-over-slf4j "1.7.25"]
[org.slf4j/log4j-over-slf4j "1.7.26"]
[org.clojure/tools.logging "0.4.1"]
Add a logback.xml with the right appenders
E.g.,
<!-- Logback configuration. See http://logback.qos.ch/manual/index.html -->
<!-- Scanning is currently turned on; This will impact performance! -->
<configuration scan="true" scanPeriod="10 seconds">
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
<include resource="logback-gcloud-appender.xml"/>
<include resource="logback-sentry-appender.xml"/>
<root level="INFO">
<appender-ref ref="GCLOUD" />
<appender-ref ref="SENTRY" />
</root>
<!-- For loggers in the these namespaces, log at all levels. -->
<logger name="user" level="ALL" />
</configuration>
And in your case the one above
+ the dependency for the appender
Now you have all Java logging rerouted to it
And you can use the Java ecosystem’s logging tooling
Proper logging is a solved problem there
I concur - Timbre is bit of an anti-java solution, which isn't necessarily bad, but for certain needs it will probably imply reimplementing solved problems as @U2PGHFU5U says
Has anyone ever seen lein compile
just hang, while cider can run the code with no issues?
If you have any top level forms in your code that execute long-running (or forever-running) code, they will be evaluated during lean compile
IIRC.
If the code in question is a server process that runs indefinitely, for example, and is started when loading the file ...
:thinking_face:
Hello, how can I invoke the ring-oauth2
middleware for every compojure-api
route?
The middleware takes this syntax:
(wrap-oauth2
handler
{:google
{:authorize-uri ""
:access-token-uri ""
:client-id "some-id"
:client-secret "some-secret"
:scopes [""]
:launch-uri "/api/oauth/google"
:redirect-uri "/api/oauth/google/callback"
:landing-uri "/"}})
And my compojure-api handler is of the form:
(def app
(api
(context "/api" []
:tags ["api"]
:middleware []
(GET "/roll/:n/:s" []
:path-params [n :- s/Int
s :- s/Int]
:return Result
:summary "Rolls :n dice of sides :s"
(ok (roll-dice n s))))))
The problem I'm facing is that I want this middleware to work across all my routes, not just for any specific route/context. I don't see an option in the documentation to make a middleware work across all routes.Wrap the compojure handler in the middleware.
greetings! is there a way to make a class instance not directly from class (symbol?), ~like this:
(let [x String]
(new x))
Syntax error (IllegalArgumentException)
Unable to resolve classname: x
maybe accomplishable by doing the work within a defmacro
either that, or resorting to java reflection...
no other way I think - new
is a Clojure special form
then next question is: is there an example of wrappers around java data records with good UX? trying to "prettify" something like this:
(case pick-var-type
:largest-domain (LargestDomain.)
:largest-max (LargestMax.)
:largest-min (LargestMin.) ...
thank you @U2FRKM4TW
@U051HUZLD This may also be of interest to you: https://github.com/plumatic/eng-practices/blob/master/clojure/20130926-data-representation.md
In general, if you don't know if something can be done in Clojure, it makes sense to first check how it could be done in Java.
.newInstance is deprecated @U051HUZLD @U2FRKM4TW
Not in Java 8. 🙂
Still, there is Constructor.newInstance()
which is a non-deprecated replacement.
But that would be what vemv has mentioned initially - resolving to Java's reflection.
(let [x String
ca (into-array java.lang.Class [])]
(-> x (.getDeclaredConstructor ca) (.newInstance ca)))
Thanks for bringing it up. I keep forgetting that it exists, probably because I've never had any use for it. But it definitely looks better than the reflection.
@amalantony you can add :middleware
to api
options too.
Thanks @U055NJ5CC. But how do I pass the second param:
{:google
{:authorize-uri ""
:access-token-uri ""
:client-id "some-id"
:client-secret "some-secret"
:scopes [""]
:launch-uri "/api/oauth/google"
:redirect-uri "/api/oauth/google/callback"
:landing-uri "/"}}
to the middleware array. It looks like the middleware array only takes middleware names.@U055NJ5CC that worked. Thank you!
An example ^{:tag (class (into-array String []))}
Do you know whether this type hint actually causes the code to perform better, or function correctly with the type hint, and be worse without it?
there are places where it can avoid reflection and thus be better
That example above is from next.jdbc.prepare
and is there to avoid reflection.
clojure.test question:
I have a repl open, I eval the test file, eval run-tests, things are fine, tests are executed.
I comment out some of those deftest
s , re-eval the file and eval run-tests, those commented out deftests are still executed. Anyone seen this before?
(deftest my-old-test nil) Do that, then delete the code.
@danvingo: deftest simply creates vars. there's nothing special about it with https://github.com/clojure/tools.namespace those vars would be gone, just like it happens wiith non-test namespaces
My solution works out if the box. no need to pull in any deps.
if you comment out the body of those deftest
it might have the intended behavior you’re after. effectively running empty tests
What does the following exception mean?
Java.lang.IllegalStateException: Attempting to call unbound fn: #'namespace-in-here/function-name
that you have (something/function-name
somewhere but that var does not have a function bound to it
If you tried to def
function-name
earlier, but an exception or perhaps some other kinds of errors occurred while evaluating the value you were attempting to "assign", then the Var function-name
can end up in an intermediate unbound state.
attempting to call it in that unbound state causes the exception message you see
(def processors
{:processor1 [function-name]
:processor2 [function-name]
:processor3 [function-name]
:processor4 [function-name]
:processor5 [function-name1 function-name2]
:processor6 [function-name]
:processor7 [function-name1 function-name3]
:processor8 [function-name1]})
; FUNCTIONS
(defn- run
"Wrap the processor function in a try/catch to prevent crashes."
[f entity]
(timbre/info "RUNNING:" f entity)
(try (f entity)
(catch Exception e
(timbre/error e))))
(defn- router
"Route a `data` map to the correct processor based on the `:processor` key."
[data]
(let [delay (:delay data)
processor (:processor data)
processors (get processors processor)]
(if (some? delay) (Thread/sleep delay) :default)
(cond (nil? processors)
(timbre/info {:message (str "NO PROCESSOR FOUND: " processor)})
:else
(doseq [processor processors]
(run processor data)))))
It works fin however, there is something going on when I remove some of the logic that gets in to the router function
Does the exception you actually see contain #'namespace-in-here/function-name
, or does it have one of the names you pasted above?
is with the functions I paste above
I just changed the names
What name do you see in the exception, exactly?
#'namespace-in-here/function-name
which is basically almost every processor
I need to recreate the issue because above code works
I did something different before calling the function router, and this same router code. and I had that exception
Is there code before what you pasted that tries to assign a value to function-name
@UM0E0PZ41 Are you working with an editor that tries to reload namespaces? I've seen that cause problems similar to what you reported. I recommend turning off all auto-reloading in editors until you really understand the "reloaded" style workflow.
(and even then I still recommend against it -- I agree with Eric Normand and Stu Halloway that such workflows are unnecessary at best and can be really confusing/problematic at worst)
What that exception means is that the var you tried to call the function from never had a function assigned to it.
(def f) (f) ;; should give a similar exception