This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-20
Channels
- # announcements (4)
- # babashka (10)
- # beginners (8)
- # calva (13)
- # cherry (20)
- # cider (9)
- # clojure (11)
- # clojure-austin (2)
- # clojure-europe (3)
- # clojure-norway (3)
- # clojurescript (1)
- # datomic (5)
- # dev-tooling (9)
- # fulcro (5)
- # hyperfiddle (5)
- # instaparse (1)
- # lingy (1)
- # malli (21)
- # matrix (1)
- # missionary (9)
- # off-topic (12)
- # releases (2)
- # ring-swagger (8)
- # scittle (9)
- # shadow-cljs (20)
I have this java class;
public static Formula of(String response, String ... predictors) {
return new Formula((Term)new Variable(response), (Term[])Arrays.stream((Object[])predictors).map(predictor -> {
if (predictor.equals((Object)".")) {
return new Dot();
}
if (predictor.equals((Object)"1")) {
return new Intercept(true);
}
if (predictor.equals((Object)"0")) {
return new Intercept(false);
}
return new Variable(predictor);
}).toArray(Term[]::new));
}
public static Formula of(String response, Term ... predictors) {
return new Formula((Term)new Variable(response), predictors);
}
public static Formula of(Term response, Term ... predictors) {
return new Formula(response, predictors);
}
/*
* Enabled force condition propagation
* Lifted jumps to return sites
*/
public static Formula of(String s) {
and cannot call the last function via (Formula/of "my string"), it fails with
No matching method of found taking 1 args for class smile.data.formula.Formula
Is there some trick to call it or is it confused by the existence of an other variadic method: public static Formula of(String response, String ... predictors)Variadic methods in java compile to methods that take an array, so to call them from clojure you have to pass an array
https://clojure.org/reference/java_interop has a variadic methods section
You're not calling it with a literal tho', right?
(~/clojure)-(!2007)-> clj -Sdeps '{:deps {com.github.haifengl/smile-core {:mvn/version "3.1.0"}}}'
Clojure 1.12.0-alpha9
user=> (import '(smile.data.formula Formula))
smile.data.formula.Formula
user=> (Formula/of "my string")
SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
SLF4J(W): See for further details.
Execution error (IllegalArgumentException) at smile.data.formula.Formula/of (Formula.java:230).
Invalid formula: my string
user=>
Can you share the actual code you're trying to run?(I tried Clojure 1.9, 1.10, and 1.11, in addition to 1.12 and can't repro your reflection failure @U7CAHM72M)
The single string method was added in 3.1.0, so maybe make sure the version of the library being used matches the source you are looking at
Did you mean 3.0.0? Confirmed that it fails in 2.6.0 but works in 3.0.0:
(~/clojure)-(!2014)-> clj -Sdeps '{:deps {com.github.haifengl/smile-core {:mvn/version "2.6.0"}}}' -M -e "(import '(smile.data.formu
la Formula))(Formula/of (str 'my_string))"
smile.data.formula.Formula
Syntax error (IllegalArgumentException) compiling Formula/of at (REPL:1:39).
No matching method of found taking 1 args for class smile.data.formula.Formula
Full report at:
/tmp/clojure-1523568482288008227.edn
Sat Apr 20 17:27:44
(~/clojure)-(!2015)-> clj -Sdeps '{:deps {com.github.haifengl/smile-core {:mvn/version "3.0.0"}}}' -M -e "(import '(smile.data.formu
la Formula))(Formula/of (str 'my_string))"
smile.data.formula.Formula
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See for further details.
Execution error (IllegalArgumentException) at smile.data.formula.Formula/of (Formula.java:230).
Invalid formula: my_string
Full report at:
/tmp/clojure-11804444325394978125.edn
Sat Apr 20 17:27:58
(~/clojure)-(!2016)->
@U064X3EF3 If I remember correctly, Clojure 1.12 has plans to address Java variadic methods, right? If not, I think it would at least deserve a more helpful hand-crafted error message because such questions pop up quite often.
We punted varargs work out of 1.12. I’m confused by the thread above what the actual problem is here
@U064X3EF3 I strongly suspect that @U7CAHM72M has the 2.6.0 version of Smile on their classpath but is looking at the 3.x source and expecting to be able to call of(String s)
which doesn't exist in 2.6.0. So the error they're getting is correct for the version they are using.
Yes, indeed. sorry for confusion. I had 2.6.0 in Classpath, but Emacs/Cider jumped somehow to 3.0.0 source code when expecting the source from Emacs.