It's just a stupid question that I had this morning : Can we use Scala classes from clojure ?
Because if the answer is yes, I'll definetly learn Clojure ^^
It's just a stupid question that I had this morning : Can we use Scala classes from clojure ?
Because if the answer is yes, I'll definetly learn Clojure ^^
Scala classes are Java classes and you can use Java classes from Clojure quite conveniently.
Have fun learning Clojure. :-)
gen-class and deftype/defrecord) can also be used from Scala. It's all bytecode underneath.blank? becomes blank_QMARK. That is because Java (or JVM?) does not support such characters in the identifiers.gen-class or, say, definterface + deftype (or defrecord) you can call your methods whatever you like. Note that Clojure itself only uses classes as an implementation detail (at a low level the user doesn't necessarily need to know about) and (at a high level) in interop scenarios. Pure Clojure code is built around totally different concepts than Java code; if you want to mix Clojure and Java / Scala class-based code, you'll likely get the best mileage by implementing solid chunks of functionality in Clojure and then exposing wrapper classes (which is fairly straightforward to do).clojure.lang.RT.var("clojure.core", "even?").invoke(2), avoiding the nasty munging. (That's equivalent to (#'clojure.core/even? 2); alternatively, you could extract the function from the Var with .get and .invoke that.)Scala classes, yes. Scala singleton objects, with the same year signature as from Java. Scala traits, no. Scala implicits, hah, you jest!
So the experience may range from "ok", if it's just your classes, to very disagreeable, in the case of Scala collections, for instance.
Worth saying that Scala classes which take function parameters, such as:
Option.map(f : A => B)
Are unlikely to be very useable from Clojure, because the Clojure compiler will not turn Clojure lambdas into instances of scala.FunctionN. I'm with Daniel - I think interop will be poor.