I don't think you are supposed to put anomalies inside an ex-info
You're supposed to return them instead. so you would not throw an anomaly, just return one
What happened to clojure.parallel ?
In the history of Clojure paper, I read > In addition to the map read/print support, Clojure has a large functional standard library ford ealing with maps, with functions for creating maps (sorted and hashed), associating and dissociating keys with values, merging, lookup, key selection and enumeration, nested map selection and update, sequencing (a seq of a map yields a sequence of key-value tuples), as well as a library implementing relational algebra on sets of maps. Of course, any map library could have these things, but no language at the time had them as pure functions of high-performance persistent HAMTs. In addition, a large subset of the map functions also work on vectors, which are, of course, also associative. What is the library implementing relational algebra on sets of maps that Rich refers to ?
yes, the fact that the relation algebra it’s more powerful than we think at the beginning, quoting Eric Normand: I don’t use these nearly as often as I should, even though I know they’re there https://purelyfunctional.tv/mini-guide/clojure-set/
from the clojure cheatsheet I think is:
Rel algebra (clojure.set/) join select project union difference intersection index rename
https://clojure.org/api/cheatsheetNice! That’s exactly what I was looking for.
Never noticed that clojure.set
provided a bit or relational algebra
yes, something that can come handy more often from now on
Hi guys, does the compile step in clojure ensure that code within an when block is able to execute, even if that path is impossible?
For some strange reason, my tests work fine locally but not when it goes through the github CI. https://github.com/zero-one-group/fxl/pull/16
I added a when block so that a block of code skips some tests if resources/credentials
does not exist (because the main repo does not have the secret updated yet
When Clojure loads a namespace, it will evaluate all top level forms. Compilation happens at load, and so will also evaluate all top-level forms. And if you perform AOT, it will in turn load everything to compile it ahead of time, and will also thus evaluate top level forms.
What you can do instead is use delay
And this happens with lein cloverage?
@didibus But where do i force/deref it such that that part doesn't become a top level form either?
Yup, it would happen with cloverage as well, when it loads the namespaces all top level will be evaluated
Something like: (defonce service (delay (gs/sheets-service google-props)))
Or: (defonce service (delay (when-not (empty? (slurp "..."))) (gs/sheets-service google-props)))
It does mean everything that uses service
now needs to deref service before using it
But it also means that the initialization of service will be delayed to the first read of the var, and no longer run at load time
What do you mean under "able to execute"?
@delaguardoI keep getting
LOAD FAILURE for zero-one.fxl.google-sheets-test
clojure.lang.Compiler$CompilerException: Syntax error compiling at (zero_one/fxl/google_sheets_test.clj:37:1).
data: #:clojure.error{:phase :compile-syntax-check,
:line 37,
:column 1,
:source "zero_one/fxl/google_sheets_test.clj"}
java.lang.IllegalArgumentException: no JSON input found
what's an idiomatic name for the constant pi/3
? For 2 pi
?
https://github.com/Tipoca/scmutils/blob/master/src/units/constants.scm#L45-L47
https://github.com/Tipoca/scmutils/blob/master/src/units/constants.scm#L33-L35
I guess tau is technically 2 pi 😅
you are checking if file exists and in the same PR you added CI step to create such file
.github/workflows/continuous-integration.yml in that file
Okay ... so hear me out, I got the exact same error from the previous commit as well
Noted! How would you name pi/4?
Cpp seems to do this https://www.quantstart.com/articles/Mathematical-Constants-in-C/
And I was using this as the check
(when-not (empty? (slurp "resources/credentials.json"))
> Okay ... so hear me out A bit rude ) I checked commit history, you added this CI step in the first commit in that branch
Sorry I didn't mean to come across as being rude
from https://clojurians.slack.com/archives/C03S1KBA2/p1609248654055300?thread_ts=1609248390.053200&cid=C03S1KBA2
• 2 pi
is not defined.
• pi/2
is M_PI_2
• 2/pi
is M_2_PI
.
So, "_ as implicit /"
Yeap I did add the CI step. So I guess the point is that I have that when because I can't add the secret needed in the main repo yet
from exception I can say only that your code is trying to read the file but found not a JSON
and as far as I see you have a check for file presence
I think you can add a bit more sophisticated check for condition in when
to check if file present and valid
So you are suggesting I might want to combine both checks? 😮
And apologies again - I was just using > Okay ... so hear me out as a figure of speech. Really do appreciate the help
yes, but I can see why this is might be an overkill ) I could also suggest to simply comment out that test until you configure the secret
I see I see! Yeahhh, i think that makes the most sense
i also wanted to ask about Clojure's compilation step
about when
?
I recall that it won't compile unused code cause of that's characteristic of the underlying jvm
but I suppose in this case, it might be because the when check depends on an external factor that so I must run the check for it?
Okay maybe that's perhaps more of google closure and unused vars if anything :thinking_face:
I think I'll just leave as this for now. Thanks again 🙂
when is a macro which expand to (if test (do body))
and if is a special form defined in clojure compiler with a promise to execute only condition and based on result execute one or another branch
I see I see
Clojure JIRA is constantly reloading for me. Is someone able to get the page working? https://clojure.atlassian.net/jira/software/c/projects/CLJ/issues
same, but this link https://clojure.atlassian.net/jira/software/c/projects/CLJ/issues/?filter=allissues is working
@delaguardo Thanks!
This is a jira bug that has been reported to atlassian
If you click on a jira issue number rather than a list item that may help
Hi Alex, thanks for your invitation. Should I file my issue or have you done that already?
no, I have not
Thanks. I have requested access to Clojure JIRA from my Atlassian account. I hope this is the right way. I found no other way to log in.
https://clojure.org/dev/dev outlines the contributor process. Note that we typically reserve jira logins for those providing patches
I already contributed to Clojure and I have a small patch for spec2.
Ok, thanks. What’s the spec 2 issue?
https://github.com/alexanderkiel/spec-alpha2/commit/48e0d17e8ddfe8cc5213256e36446dde212c5f9b
FYI, core team is all on vacation this week. I will check in at some point but might not be today
No problem. I wish you a happy new year and will come back to you next year.
Hey all! I”m mostly done with a fairly advanced forward-mode automatic differentiation implementation in Clojure - this was fairly subtle, but the implementation is shaping up to be nice and usable outside of my initial goal / library
basically this lets you augment a bunch of operations like +, -, *, /, log, exp, etc, and turn them into functions you can “differentiate” through - ie, given some f
that uses the new augmented fns, (D f)
will return a NEW function that, given an input, returns a measure of how sensitive the result is to that input
I wrote it in literate-programming style, so wanted to poll here and see if there was anyone interested in watching / attending a live tour of how to build something like this
here’s current status for anyone curious, working great but not quite tidied. Cheers and hope everyone’s doing well over the holidays! https://github.com/sicmutils/sicmutils/blob/81509823023a39553f2f3a5eab7571ab0b986cd6/src/sicmutils/differential.cljc
REPL friendly code question. I have the following code:
(defn app
[]
(create-ring-handler))
(defmethod ig/init-key :system/http-server [_ {:keys [db-spec opts]}]
(jetty/run-jetty #'app opts))
The above works nicely. I can re-eval all code defined in app
(for example, all the handlers) and jetty picks everything up.
I would like to pass around a db-spec
explicitly now like this:
(defn app
[db] <--- note db
(create-ring-handler db))
(defmethod ig/init-key :system/http-server [_ {:keys [db-spec opts]}]
(jetty/run-jetty #'app opts)) <-- need to pass db-spec to #'app
is it possible to pass runtime params, like db-spec, to the var quoted app
in the multimethod? Or maybe i need to restructure more of my code :thinking_face:> You could wrap the middleware call: (jetty/run-jetty (fn [req] ((wrap-config #'app config) req)) opts)
-- I think that would work
I have been trying that with no problem until I started using CSRF protection (i.e. ring-anti-forgery), which needs to maintain state across requests
you could disable CSRF protection while in development (and I wouldn't rebuild the whole handler on every request in production anyway)
esp. when using reitit, which IIUC does some sort of "precompilation" of the routes for speed
another workaround would be to keep a ring session store across handlers (e.g., pass that as part of the config
)
🎉
I would not have expected that first example to work: run-jetty
expects a Ring handler function and handlers should always accept the Ring request hash map as their single argument @tkjone
The usual approach in cases like this is to use middleware to wrap #'app
and that middleware accepts the various system information and adds it into the Ring request hash map prior to calling the handler:
(defn wrap-config [h config] (fn [req] (h (assoc req ::config config)))
(defmethod ig/init-key :system/http-server [_ {:keys [opts] :as config}]
(jetty/run-jetty (wrap-config #'app config) opts))
something like that, maybe? (edited to add config
as an arg to wrap-config
)ooops, yeah, you are correct about the first snippet…I oversimplified my actual code sample too much 😞
Note that in the above, once you have started the server, you can't change that middleware without a restart but you can still change the handler.
You could wrap the middleware call: (jetty/run-jetty (fn [req] ((wrap-config #'app config) req)) opts)
-- I think that would work.
Interesting. I will attempt both of those. Good to know.
I was thinking in a different way where I was trying to just pass in config
to reitit and attach to their :data
hash map and that’s what threw me off
As always, thank you Sean!!
Ah, I've never used reitit
so I don't know if it has anything to make that sort of handler wrapping easier (nor whether it is REPL-friendly).
No, not specifically from what I can tell, so your approach is still valid.
the integrant README has an example setup that would let you reload the middleware too (but you'd have to explicitly suspend and resume; just reloading the handler wouldn't do): https://github.com/weavejester/integrant#suspending-and-resuming