clojure and scala interop

最后都变了- 提交于 2019-12-23 06:56:41

问题


I am familiar that scala classes / objects can be called from clojure, as scala compiles to bytecode, and clojure is comfortable with it.

However is it as painless calling clojure functions, and importing namespaces from scala ?

I would like to mix the excellent lift framework and clojure, basically call clojure code from lift.


回答1:


Semantics for imports in Scala are basically the same as Java. You should be able to get the info you need by reading up on how to invoke Clojure code from Java, then apply the same principles in Scala.

If you want to compile your Clojure code and include it as a JAR in your classpath then this post should be relevant:

Calling Clojure from Java

If you'd rather dynamically compile/interpret the .clj files then you should read this:

Clojure Programming: Invoking Clojure from Java

The first option seems a lot nicer to me.




回答2:


FWIW, I had a similar experience recently. It is not always straight forward to consume scala libraries in a clojure codebase. If the library authors have kept the none scala consumers in mind while designing the api, the integration can be trivial. If not you may have to learn the details of what java interface is produced by the scala library you are trying to consume.

I recently wrote a documentation about this exact topic (https://github.com/grandbora/clojure-scala-cantrips#clojure-scala-cantrips) and there are some clojure libraries out there that provides sugar syntax for consuming scala libraries.



来源:https://stackoverflow.com/questions/11928872/clojure-and-scala-interop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!