Calling Scala from Clojure
In this recipe, we will integrate Clojure and Scala. We will configure a mixing project using Leiningen.
Getting ready
We create a project by lein new clojure-scala
and project.clj
as follows:
(defproject clojure-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.8.0"] [org.scala-lang/scala-library "2.11.7"]] :plugins [[io.tomw/lein-scalac "0.1.2"]] :scala-source-path "src/scala" :scala-version "2.11.7" :prep-tasks ["scalac"] :main clojure-scala.core )
After modifying the project.clj
, start the REPL.
How to do it...
We will explain how Clojure code calls Scala methods and how to access fields defined in Scala. We will use Leiningen and the plugin for Scala. This assumes...