I understand that their is Clojure the sits on the JVM in which you can use Java libraries. Also, there is ClojureScript which allows you to use JavaScript libraries, but is it possible to mix libraries from each in one Clojure file / project?
Asked
Active
Viewed 761 times
2
-
4https://github.com/clojure/clojurescript/wiki/Using-cljc – Timothy Pratley Sep 25 '16 at 01:27
-
Given that Java JDKs including JavaScript engines (Rhino and Nashorn in different Java versions) ... I suspect that it might be possible to run ClojureScript from within your JVM. (Quick Google search on "ClojureScript in Nashorn" yields: https://github.com/bodil/cljs-nashorn) I don't know how many JavaScript libraries are useable in any meaningful way from within the JVM vs within a browser or in Node.JS. – Jim Dennis Sep 25 '16 at 07:49
-
2here is an example project that uses both clojure and clojurescript https://juxt.pro/blog/posts/edge.html https://github.com/juxt/edge/blob/master/README.md – CandiedCode Sep 26 '16 at 09:40
1 Answers
0
You can write Clojure in .cljc files which can be read by both Clojure and ClojureScript. Any platform specific code can be wrapped in Reader Conditionals so it is only read on the host platform. Many libraries support cljc, though they do need to be converted, and it may not always make sense to do so if there is not a lot of common code between the two. See http://clojure.org/guides/reader_conditionals for more information.

Daniel Compton
- 13,878
- 4
- 40
- 60