clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
Linus Ericsson 2021-06-11T09:46:59.296Z

We get the following error when doing some xml-stuff (having [com.fasterxml.jackson.core/jackson-core "2.12.3"] [org.clojure/data.xml "0.2.0-alpha6"] [clj-xml-validation "1.0.2"] as xml-related libs, WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by clojure.lang.InjectedInvoker/0x00000008401e8040 (file:/home/X/Y/Z/local-m2/org/clojure/clojure/1.11.0-alpha1/clojure-1.11.0-alpha1.jar) to method http://com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema(http://com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool) WARNING: Please consider reporting this to the maintainers of clojure.lang.InjectedInvoker/0x00000008401e8040 WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release What can it be, what can we do about it?

kwladyka 2021-06-11T09:55:10.296200Z

I am not sure, but I would guess Java version

kwladyka 2021-06-11T09:55:27.296400Z

Try Java 8 or use different versions of libraries

Linus Ericsson 2021-06-11T10:05:27.299300Z

We will keep the JDK version because of alpn-features etc. So far this is a warning, but it would be nice to get it sorted ofc

lassemaatta 2021-06-11T10:23:40.299500Z

https://clojure.org/guides/faq#illegal_access gives some background on the issue

๐ŸŽ‰ 2
zendevil 2021-06-11T10:25:48.300300Z

What is the access and assoc time complexity of a Clojure vector?

2021-06-11T10:42:11.300700Z

It's O log32 n. Its a shallow tree with 32 element wide nodes. So maximum deepness would be 7. Assoc means creating up to 7 arrays of 32 elements, on huge vectors.

alexmiller 2021-06-11T12:26:34.303300Z

Note that this reports as Clojure because itโ€™s a code generated by Clojure but thatโ€™s probably not the actual source. Use the debug setting talked about there to pinpoint the actual source

alexmiller 2021-06-11T12:28:10.304700Z

Itโ€™s wherever newSchema is being called - adding a type hint to the interface is probably sufficient there

zendevil 2021-06-11T15:26:45.309100Z

Can somebody point me to the Clojure source locโ€™s where vectors are implemented?

vncz 2021-06-11T16:14:13.311500Z

I am looking at clj-http and I am trying to understand the retry logic; is there anything included about backoffs, retries on specific status codes?

vncz 2021-06-11T16:14:42.311800Z

Something on the same line of https://findwork.dev/blog/advanced-usage-python-requests-timeouts-retries-hooks/#retry-on-failure โ€” which is very very well done

lukasz 2021-06-11T16:16:28.312Z

:retry-handler is what you're after - it doesn't do much but you can plug in your own retry logic there

vncz 2021-06-11T16:17:21.312200Z

Yeah I noticed about it. Iโ€™m just lazy to write all that kind of logic that is built in the Python library :trollface:

lukasz 2021-06-11T16:21:19.312400Z

There might be some repos/gists laying - worth searching, you can turn the problem inside out and use libs like https://github.com/joelittlejohn/clj-http-hystrix (or something simpler)

2021-06-11T16:21:25.312700Z

@ps Its pretty complex code. https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentVector.java (APersistentVector is a abstract) If your goal is to understanding the algorithm I think I made a simpler to understand implementation in F#, lacking some features like e.g. transients. It doesn't use boxing and is hence homogeneously typed. https://github.com/stefanvstein/fsgrit/blob/master/Vector/Vector.fs. Rich has made excellent videos on how it works.

vncz 2021-06-11T16:22:02.313100Z

Oh that looks interesting, thank you

Darin Douglass 2021-06-11T17:31:34.313400Z

https://github.com/joegallo/robert-bruce or https://github.com/BrunoBonacci/safely are also available as generic retry libs

Miguel Rivas 2021-06-11T18:40:43.316Z

Hi there, how can we get the namespace of a function? Is there any way to achieve this from this context using alter-var-root?

(defn my-wrapping-fn
  [function]
  (alter-var-root function
                  (fn [f]
                    (fn [& n]
                      (let [f-namespace ??? ;; want to get f's namesapce here
                            result (apply f n)]
                        result)))))

borkdude 2021-06-11T18:43:18.316900Z

@mrivas616 Usually only vars carry the namespace metadata, so you'd have to retain a reference to the var, not the function it holds

borkdude 2021-06-11T18:43:53.317300Z

But if you have that, then it's (:ns (meta the-var))

borkdude 2021-06-11T18:44:29.317600Z

e.g.:

user=> (:ns (meta #'inc))
#object[clojure.lang.Namespace 0x75f2099 "clojure.core"]

borkdude 2021-06-11T18:45:11.318200Z

you can call ns-name on that to get clojure.core as a symbol

Miguel Rivas 2021-06-11T18:45:37.318700Z

Gotcha, thanks ๐Ÿ˜„ :thumbsup:

borkdude 2021-06-11T18:46:23.319500Z

there is a hack to retrieve the ns symbol from the munged function name, but it's a bit of a low level / possibly unsupported hack. it's used in clojure.spec.alpha

๐Ÿ‘€ 1
๐Ÿ˜ฎ 1
Ed 2021-06-11T18:47:19.319800Z

you can call .ns on the var as well as getting it from the metadata

๐Ÿ‘‹ 1
borkdude 2021-06-11T18:48:27.320300Z

not really portable across implementations though but maybe that's not a concern

๐Ÿ‘ 1
Miguel Rivas 2021-06-11T19:15:17.322100Z

Is there any reason/advantage on using (clojure.lang.Compiler/demunge) instead of (clojure.main/demunge)? :thinking_face: taking a look at the code in clojure.spec.alpha

blak3mill3r 2021-06-11T19:44:32.323200Z

That might possibly be an optimization. That's only a guess. Got a link to the code?

Miguel Rivas 2021-06-11T19:49:34.323700Z

Yeah, I was thinking the same :thinking_face: here is the code for context: https://github.com/clojure/spec.alpha/blob/master/src/main/clojure/clojure/spec/alpha.clj#L135

2021-06-11T20:01:48.324Z

namespaces are a property of a function

2021-06-11T20:02:08.324200Z

a function is a value, like the number 5

2021-06-11T20:02:52.324400Z

when you (def x 5) 5 doesn't know about about x and doesn't know about the namespace x is in