This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-07-08
Channels
- # beginners (52)
- # boot (230)
- # cider (67)
- # clojure (166)
- # clojure-canada (1)
- # clojure-dev (91)
- # clojure-japan (6)
- # clojure-korea (1)
- # clojure-russia (2)
- # clojure-uk (10)
- # clojurescript (222)
- # core-async (27)
- # datomic (5)
- # editors (13)
- # euroclojure (12)
- # ldnclj (10)
- # off-topic (12)
- # om (16)
- # onyx (4)
- # other-lisps (2)
- # overtone (1)
- # re-frame (4)
- # sim-testing (1)
i have a patch candidate for CLJ-1449 http://dev.clojure.org/jira/browse/CLJ-1449 if anyone has some feedback for me
quick glance, the interop calls (indexOf, etc) aren't defined on CharSequence ,but on String
ok reading https://github.com/clojure/clojure/blob/master/src/clj/clojure/string.clj#L33 .. i understood to use CharSequence but it possible i don’t fully understand
clojuregeek: it seems that a lot of the functions in clojure.string cast from CharSequence -> String through .toString
for starts-with?
for example, it takes a string, value and returns boolean .. i looked at how blank?
was implemented .. takes a CharSequence.. returns a boolean
there is a difference though, blank? only calls .charAt and length, both of which are defined on CharSeq
so all the new functions need to use ^String not ^CharSequence ?
these are new methods to be added to clojure.string
where in blank? is it casting s as String ?
it doesn't cast in blank? because blank? happens to have everything necessary on CharSequence
ok i see triml
casts to a string
so in index-of i need to cast it to a string before i can call indexOf ?
just want to say +1 to ghadi's comments
another approach would be to reimplement indexOf in clojure, but I think that might be poopooed upon
also, you have added "1.9" - should be 1.8
ghadi: yeah, we should just call java here
ok I didn’t know how long it would take to get accepted
well let's assume 1.8 :)
you can test with StringBuffer/StringBuilder instances for something that is a CharSequence but not a String
is this correct? when you pass a char to index of?
332 │ (if (char? value)
333 │ (.lastIndexOf s (int value))
334 │ (.lastIndexOf s value)))
that should work (although I'd verify by looking at the byte code)
you could also do (.lastIndexOf s ^char value)
ok how would i look at the byte code?
"mvn clean compile" to build clojure
then: javap -c -classpath target/classes clojure.string\$index_of
you might want to pipe that into an editor
then check out the invoke methods
I'm happy to get on skype and walk through it with you or something
my book went to production today and I haven't slept much this week - sorry for not responding to your email :)
oh its ok!! no problem!!
also, try adding (while doing dev): (set! warn-on-reflection true) to the top of that ns - you'll see it's generating a bunch of warnings from your changes right now
those should have been around warn-on-reflection, not bold text :)
got it
ok i see the warnings. I was going to say.. it ‘appeared to work’ on CharSequences so I was puzzled
well stringbuffer for example cleverly implements the same methods as string for things like indexOf, but CharSequence does not define it
clojure will generate the proper invocation and it will succeed in both cases - jvm ftw :)
I would add that smaller arity impl could just call greater a arity ones, to avoid duplication of code (since they are essentially the same). Not sure how much overhead this could impact
clojuregeek: actually without hints, it's just going to make a reflective call on the instance, so you don't want that
in the byte code you can see "Method clojure/lang/Reflector.invokeInstanceMethod" - you don't want to see that :)
this?
[java] Reflection warning, clojure/string.clj:324:6 - call to method indexOf on java.lang.String can't be resolved (argument types: unknown).
[java] Reflection warning, clojure/string.clj:327:5 - call to method indexOf on java.lang.String can't be resolved (argument types: int, unknown).
[java] Reflection warning, clojure/string.clj:328:5 - call to method indexOf on java.lang.String can't be resolved (argument types: unknown, unknown).
yeah, that's the warning - I was referring to the bytecode on the last one, but saying the same thing either way
andrewhr: my guess is that the fastest path is to get the right args to the right java.lang.String method as directly as possible and then let the jit do its thing.
that is, I am more concerned about performance than duplication in this case
clojuregeek: reading java docs I learned that indexOf
doesn't care about fromIndex
bounds: they could be negative or greater than actual string length. What do you think about expressing this behavior on the tests themselves? Worth the trouble?
part of my thinking on the tests was, the decisions i do (if char?) should be fully tests .. but testing the output of the javaop doesn’t need to be tested here, those tests should be done on java side .. so i held back some on my test obsessiveness : )
I think I'd say it does care about it but has well-defined semantics when it is <0 or >length. seems like those should be covered in the tests.
you don't need to verify the output of javap
but I use it to ensure the compiled version really is doing what I expect in a method like this in the std lib that I would expect to get called a lot
it might be advisable to leave the (set! ) call in the patch so warnings would show up - we do that in many other places in core
ok i’ll leave the set in the patch
it would be fun to think about test.check properties for these too
start with a string, generate another arbitrary string including the first string, then verify that the original string can be found
i would love to do those kinds of tests…
test.check is a dependency and we are trying to write more of them
ok i am not understanding this type hinting, so if you have time to do a call i think that would help me
would this be the way I would need to refer to my locally compiled version of clojure? https://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md#checkout-dependencies … just want to make sure I don’t spend hours going down a molehill
clojuregeek: you have a couple options here. Simplest: mvn clean package
then look in the target/
directory
ok, and if I wanted to have that as a dependency in a new clojure project?
change the version number in pom.xml
, then mvn clean install
, then refer to that version from a separate project
ok cool, thanks. I wanted to do some benchmarking with criterium
@ghadi: I get this error:
java.lang.IllegalArgumentException: Bad artifact coordinates org.clojure:clojure:jar:clojure 1.8.1, expected format is <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>
at org.sonatype.aether.util.artifact.DefaultArtifact.<init> (DefaultArtifact.java:73)
org.sonatype.aether.util.artifact.DefaultArtifact.<init> (DefaultArtifact.java:56)
`
I have this in pom.xml and build, install
<version>1.8.1-master-SNAPSHOT</version>
i see the jar file in my m2 directory
i figured it out, imadork
the name didn’t match exactly
thanks for your help i’m gonna blog about it so i can find it again when I google