Fork me on GitHub
#clojure
<
2020-08-29
>
souenzzo00:08:20

How do I type hint int ? (to avoid reflection warn) I'm using ^long and it works but not sure if it right or luck

dpsutton00:08:12

you can use ^java.lang.Integer if you actually want an integer. (type (int 3)) is how i got the class. not sure what type you actually need though

dominicm09:08:45

Why don't sets support dissoc? It seems that they could implement the "without" requirement easily (other than the obvious answer of it being in a diff interface)

rutledgepaulv12:08:45

There's clojure.core/disj for that if you weren't already aware.

dominicm12:08:08

I am. I'm implementing my own collection protocol, and it has a key removal method. I've partially copied core, but I've differed here.

cjsauer14:08:09

I’ve often wondered this as well. Maybe dissociation is semantically reserved for associative data types? It’s a weak argument tho, because a set can be considered a map of a key to itself if you squint a bit. Does dissoc have different perf guarantees than disj?

andy.fingerhut18:08:34

dissoc on hash maps, and disj on hash sets, have pretty much the same performance guarantees, and even pretty much the same implementation in Clojure/Java

andy.fingerhut18:08:46

I do not know the reasons for dissoc not being supported on sets, but disj definitely does that. While the underlying implementation of Clojure/Java sets is maps from keys to themselves, that seems to be an implementation technique, and there is no other attempt I am aware of in any Clojure functions to make sets 'look like' maps from keys back to themselves.

michael_teter14:08:58

Pedestal users - I notice some of the guides on http://pedestal.io are from 2016. Do they still represent the right way to build with Pedestal?

Alex Miller (Clojure team)15:08:22

afaik, those are still up to date

Alex Miller (Clojure team)15:08:29

doc issues can be asked here https://github.com/pedestal/pedestal-docs/issues if you find otherwise

🙏 3
Alexis Vincent16:08:00

Hi there, I’m struggling with some Java interop. I want to list a bunch of gcp projects in clojure. Trying to replicate the following call: https://github.com/googleapis/java-resourcemanager#listing-all-projects So using com.google.cloud/google-cloud-resourcemanager {:mvn/version "0.118.0-alpha"}, I have the following source

(ns project
  (:import  [com.google.cloud.resourcemanager
             ResourceManager
             ResourceManagerOptions
             Project]))

(set! *warn-on-reflection* true)

(def ^ResourceManager resource-manager (-> (ResourceManagerOptions/getDefaultInstance) .getService))

(-> resource-manager
    (.list))
But this blows up with
1. Unhandled java.lang.IllegalArgumentException
   No matching field found: list for class
   com.google.cloud.resourcemanager.ResourceManagerImpl
And
(clojure.pprint/pprint (clojure.reflect/reflect resource-manager))
yields
{:bases
 #{com.google.cloud.BaseService
   com.google.cloud.resourcemanager.ResourceManager},
 :flags #{:final},
 :members
 #{...
   {:name list,
    :return-type com.google.api.gax.paging.Page,
    :declaring-class
    com.google.cloud.resourcemanager.ResourceManagerImpl,
    :parameter-types
    [com.google.cloud.resourcemanager.ResourceManager$ProjectListOption<>],
    :exception-types [],
    :flags #{:varargs :public}}
...}}
Any idea what I should be doing above and beyond the java example?

dpsutton16:08:21

https://github.com/googleapis/java-resourcemanager/blob/master/src/main/java/com/google/cloud/resourcemanager/ResourceManager.java#L233 shows the signature is a varargs one. the java compiler does some niceties with this but clojure requires that you pass an empty array of ProjectListOption here

Alexis Vincent16:08:03

@dpsutton Thanks! Assuming this is particular to varargs and clojure

dpsutton16:08:10

yeah. let me find a good link

dpsutton16:08:17

i don't see it on https://clojure.org/reference/java_interop and that seems like an omission worth correcting

Alexis Vincent16:08:28

Appreciate the help. I haven’t written java since 2014, and I haven’t needed to do much interop either.

Alexis Vincent16:08:54

Excellent!

(-> resource-manager
    (.list (into-array ResourceManager$ProjectListOption [])))
Worked

Alexis Vincent16:08:44

Appreciate it! Agree, should be in interop. I’m pretty sure this tripped me up before. And the first place I looked today was https://clojure.org/reference/java_interop

dpsutton16:08:01

ah i looked but not hard enough. thanks

kenny16:08:55

I also agree the content should be added to the Java interop page. Feels like the first place someone would look.

dpsutton16:08:20

added that note to the issue. thanks @kenny

dpsutton16:08:39

and for sure, if something merits to be in the frequently asked questions it should be in the reference part 🙂

emccue19:08:13

on that note, it would be nice to not have to care as much

Alex Miller (Clojure team)22:08:10

For sure but as you can see on the ticket, there are a lot of edge cases

Eugene Koontz21:08:35

hi folks, hitting a 8192-character limit for text within tags when parsing xml documents. The JDK’s built-in streaming parser can’t handle documents like <foo>text…</foo where the text.. is longer than 8192 characters. I made a git repo to illustrate the problem: https://github.com/ekoontz/xml-stream-buffer/blob/master/README.md

Eugene Koontz21:08:01

I looked around in the https://github.com/openjdk/jdk/blob/master/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLStreamReaderImpl.java to find a property to supply to the JVM to override that limit, but can’t find what the property name is to modify it

Eugene Koontz21:08:00

there must be some way to overcome this hardwired limit, though..?

seancorfield21:08:42

This also mentions the limitation and suggests switching to a different type of parse, on casual reading https://stackoverflow.com/questions/22891411/java-xerces-java-lang-arrayindexoutofboundsexception-8192

Eugene Koontz21:08:24

thanks for those links! reading..

seancorfield21:08:53

Hmm, not sure the first answer is relevant (but it's curious that it has a property-based way to extend the limit beyond 8192).

Eugene Koontz21:08:00

for the first link, i don’t see XmlDictionaryReaderQuotas in the JDK source code, so I guess it’s not relevant for this case

Eugene Koontz21:08:05

the second link is interesting because I’m also trying to read wiktionary XML, which has very long text sections (not excessively long, just longer than 8k)

Eugene Koontz21:08:05

yes, now I remember seeing this second link from stackoverflow..recommends switching to a different SAX implementation. I guess I’ll try that, but I’m surprised this limitation is hard-wired in the bundled JDK implementation

seancorfield21:08:48

What JDK version are you using?

Eugene Koontz21:08:48

but hit the same exception with jdk 12 and 13

seancorfield21:08:29

Ah, from that JDK bug report it sounded like it was fixed in later JDKs (but it also said it was an upstream Xerces bug and I haven't tracked that any further).

Eugene Koontz21:08:58

yes, looking at the xerces properties, i don’t see anything that would help: https://xerces.apache.org/xerces2-j/properties.html

Eugene Koontz21:08:17

wow, 12 years later!

Eugene Koontz21:08:43

yeah i guess my best strategy is to engage with the xercesj community and build the library with whatever fix can be developed, and use that in my classpath

Eugene Koontz21:08:28

also mentions wikipedia XML dumps, a common theme for this problem

Eugene Koontz21:08:32

but then i wouldn’t have the nice clojure integration that data.xml gives us

Eugene Koontz13:08:39

figured it out! using https://fasterxml.github.io/woodstox/javadoc/5.0/com/ctc/wstx/api/WstxInputProperties.html#P_INPUT_BUFFER_LENGTH fixes it..i’ll post some updates to my above repo when I clean it up.

seancorfield18:08:40

Contrib libraries do not accept PRs, FYI. See https://clojure.org/community/contributing -- Contrib libraries operate under the same process as Clojure itself.

👍 3
Eugene Koontz18:08:19

thanks for the reminder - I think I remember signing the agreement years ago, but haven’t had anything to contribute until now

Eugene Koontz18:08:59

although, i wonder if it will be accepted, given that it brings in another dependency (woodstox)

seancorfield18:08:43

Check whether you have JIRA account with ticket creation permissions. If not, you'll need to create a post on http://ask.clojure.org to discuss the issue. I suspect adding a dependency to clojure.data.xml would not be accepted, although some Contrib libraries do have external dependencies... You'd have to discuss it Alex and probably Herwig who is the official maintainer (although the library is marked Stable, rather than Active).

Eugene Koontz18:08:41

yes - i still have a JIRA account, yay!

Eugene Koontz18:08:05

and I can create tickets

seancorfield18:08:22

Cool. That's one step shorter to getting a discussion going about it 🙂

Eugene Koontz19:08:35

thanks for the discussion on this! enjoyed it.

zackteo22:08:14

Hey guys! Not sure if this is the right channel for this but wanted to get some thoughts. So I happened to see this Clojure question on Stackexchange via Zulip. And thought hey maybe I could give a shot at answering. Okay, wanted to actually comment at first, given that the qn wasn't too clear ... but couldn't cause I haven't accumulated enough rep >< So granted, I ended up giving a short half answer/half question in my original response which okay fine I got 1 downvote for. But because of the comment not to ask questions, I rephrased my answer and gave quite a bit of due thought to trying to tackle it? But, I ended up finding that 2 people deleted my answer? 😕 Maybe it is because an answer can't be provided before clarification? I don't know? Just me trying to rationalise if I am justified to feel a bit angry or annoyed. Any thoughts? 😮 (Also should I undelete my answer?) https://stackoverflow.com/questions/63642728/how-to-convert-from-a-string-into-an-argumentfunction-using-clojure?answertab=active#tab-top

seancorfield22:08:49

It's fine to feel annoyed at suffering inflicted by the Moderation Overlords at StackOverflow 🙂

seancorfield22:08:54

I know a lot of people who've had answers and/or comments deleted and/or downvoted. SO is kind of a strange beast.

zackteo22:08:56

Also should I be undeleting my answer? Yeah @seancorfield I kinda felt that way ><

seancorfield22:08:01

I wouldn't try to rationalize it or take it personally. Just chalk it up to folks on the Internet being somewhat trollish and move on.

seancorfield22:08:46

I have sufficient rep on SO to be asked to review all sorts of stuff and so I see a lot of questions and answers that have been flagged. Some deserve it, most don't, but there are so many moderators that it doesn't take much to get "hit" by a small number of them and feel aggrieved 😐

seancorfield22:08:14

That particular case is a very poorly-worded question so pretty much any attempt to answer it is going to get moderated.

zackteo22:08:16

Do you think I should click on the undelete button then? Not sure how the "Vote to undelete this post? (5 votes remaining)" works

zackteo22:08:30

I see I see o:

seancorfield22:08:48

Ignore it and move on. It really isn't worth you expending energy or worrying about it.

zackteo22:08:25

Thanks for your advice! 🙂

seancorfield22:08:45

But I don't think your post here belongs in #clojure because it's not about Clojure -- #off-topic would have been a better choice.

zackteo22:08:19

Is there no way to move posts?

seancorfield22:08:42

You can share it into #off-topic and then delete it from here I believe.

zackteo22:08:02

Should I do that then or just delete it entirely?

seancorfield22:08:19

That's up to you.

seancorfield22:08:11

:thumbsup::skin-tone-2:

seancorfield22:08:04

Funnily enough I just went through a review session of "poor answers" and saw exactly that same comment from moderators that you got on yours.

seancorfield22:08:27

And some answers I really had to recommend to just delete without comment.

ozzloy23:08:35

is there a more idiomatic way of toggling set membership? right now i'm doing this: ((if (contains? some-set element) disj conj) some-set element)

stephenmhopper23:08:35

Is anyone here familiar with the clj-soap library that was originally created by @seancorfield? I’d like to open an issue on it, but the root project is archived and the current fork that the archive points to doesn’t have issues enabled. I believe I need to use the :complex-args true option as mentioned in the documentation, but I can seem to find an example of how it works

seancorfield23:08:53

@stephenmhopper I did not create it. I forked it from the original author who had abandoned it.

stephenmhopper01:08:54

Okay, thanks for the explanation!

seancorfield23:08:04

I just got it working with a more modern version of Clojure but I could never get it to work with the web services we needed to use, so I archived it since I could not get it to work and I couldn't maintain it.

seancorfield23:08:00

It looks like Zeto-Ltd has also abandoned it at this point.

seancorfield23:08:10

What we had to do in the end was use wsdl2java to generate Java source classes from the web service itself, then compile those into a library, and use it directly via interop from Clojure.