Since Clojure runs on the JVM, you can access any known class which is on your classpath out of Clojure. Here is a Scala example. To make the classpath setup and dependency management easier, use Leiningen to generate a project.
lein new clojure-scala
In the project folder, modify the project.clj and add a dependency for Scala's language libraries, and the scala-src folder to the classpath:
(defproject clj-scala "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.3.0"]
[org.scala-lang/scala-library "2.7.1"]]
:compile-path "scala-src" )
Create the directory scala-src, and in that folder create the following Scala class:
class HelloWorld {
def sayHelloToClojure(msg: String) =
"Here's the echo message from Scala: " concat msg
}
Compile the class using scalac. Now run lein deps to download the dependencies. Launch the Clojure REPL by running lein repl. You can import the Scala class, instantiate it and call the sayHelloToClojure method.
user=> (import HelloWorld)
HelloWorld
user=> (.sayHelloToClojure (HelloWorld.) "Hi there")
"Here's the echo message from Scala: Hi there"
This is just compatible to the way you could use Scala classes and code out of Java. That can get tricky, a quote from the Frequently Asked Questions - Java Interoperability:
Using a Scala class from Java can get tricky, in particular if your
Scala class uses advanced features like generics, polymorphic methods,
or abstract types. Since Java doesn't have such language features, you
have to know something about the encoding scheme of Scala classes.