This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-29
Channels
- # admin-announcements (1)
- # announcements (3)
- # babashka (18)
- # beginners (35)
- # cider (4)
- # clj-kondo (52)
- # cljs-dev (2)
- # clojure (92)
- # clojure-spec (18)
- # clojurescript (17)
- # conjure (11)
- # core-async (1)
- # datomic (11)
- # emacs (5)
- # fulcro (11)
- # graalvm (10)
- # helix (21)
- # kaocha (6)
- # malli (1)
- # membrane (37)
- # off-topic (110)
- # re-frame (1)
- # reagent (12)
- # reitit (5)
- # rewrite-clj (1)
- # sci (1)
- # shadow-cljs (40)
- # vim (21)
- # vrac (17)
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
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
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)
There's clojure.core/disj
for that if you weren't already aware.
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.
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?
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
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.
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?
afaik, those are still up to date
doc issues can be asked here https://github.com/pedestal/pedestal-docs/issues if you find otherwise
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?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
@dpsutton Thanks! Assuming this is particular to varargs and clojure
i don't see it on https://clojure.org/reference/java_interop and that seems like an omission worth correcting
Appreciate the help. I haven’t written java since 2014, and I haven’t needed to do much interop either.
https://github.com/seancorfield/depstar/blob/develop/src/hf/depstar/uberjar.clj#L43 is an example of the created array and a usage at https://github.com/seancorfield/depstar/blob/develop/src/hf/depstar/uberjar.clj#L111
Excellent!
(-> resource-manager
(.list (into-array ResourceManager$ProjectListOption [])))
WorkedAppreciate 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
upvoted
I also agree the content should be added to the Java interop page. Feels like the first place someone would look.
and for sure, if something merits to be in the frequently asked questions it should be in the reference part 🙂
For sure but as you can see on the ticket, there are a lot of edge cases
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
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
there must be some way to overcome this hardwired limit, though..?
Does https://www.codeproject.com/questions/634305/the-maximum-string-content-length-quota-8192-has-b help?
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
thanks for those links! reading..
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).
for the first link, i don’t see XmlDictionaryReaderQuotas
in the JDK source code, so I guess it’s not relevant for this case
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)
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
What JDK version are you using?
jdk 14
but hit the same exception with jdk 12 and 13
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).
yes, looking at the xerces properties, i don’t see anything that would help: https://xerces.apache.org/xerces2-j/properties.html
https://issues.apache.org/jira/browse/XERCESJ-1257 (the referenced bug) got reopened.
wow, 12 years later!
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
also mentions wikipedia XML dumps, a common theme for this problem
or maybe use the wikipedia java tool: https://www.mediawiki.org/wiki/Manual:MWDumper
but then i wouldn’t have the nice clojure integration that data.xml gives us
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.
diff is here: not yet ready for a PR though. https://github.com/clojure/data.xml/compare/master...ekoontz:woodstox?expand=1
Contrib libraries do not accept PRs, FYI. See https://clojure.org/community/contributing -- Contrib libraries operate under the same process as Clojure itself.
thanks for the reminder - I think I remember signing the agreement years ago, but haven’t had anything to contribute until now
although, i wonder if it will be accepted, given that it brings in another dependency (woodstox)
we’ll see
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).
yes - i still have a JIRA account, yay!
and I can create tickets
Cool. That's one step shorter to getting a discussion going about it 🙂
thanks for the discussion on this! enjoyed it.
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
It's fine to feel annoyed at suffering inflicted by the Moderation Overlords at StackOverflow 🙂
I know a lot of people who've had answers and/or comments deleted and/or downvoted. SO is kind of a strange beast.
Also should I be undeleting my answer? Yeah @seancorfield I kinda felt that way ><
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.
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 😐
That particular case is a very poorly-worded question so pretty much any attempt to answer it is going to get moderated.
Do you think I should click on the undelete button then? Not sure how the "Vote to undelete this post? (5 votes remaining)" works
Ignore it and move on. It really isn't worth you expending energy or worrying about it.
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.
You can share it into #off-topic and then delete it from here I believe.
That's up to you.
:thumbsup::skin-tone-2:
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.
And some answers I really had to recommend to just delete without comment.
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)
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
@stephenmhopper I did not create it. I forked it from the original author who had abandoned it.
Okay, thanks for the explanation!
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.
It looks like Zeto-Ltd has also abandoned it at this point.
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.