Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Clojure libraries can I use if I plan to use the clojurescript compiler?

I'm new to Clojure but my end goal in learning the language is to use the Clojurescript compiler, since I plan on using the generated code on the browser VM.

Since there tutorials are abundant for Clojure and Clojurescript is just another compiler I'm doing the Clojure tutorials, but now I got to a point where I want to know where is the line between the libraries that are core clojure that will compile to javascript fine and the ones that won't.

For example, in the tutorial I'm following for Clojure I was reading this but it seems this is already using deep Java objects, and not core Clojure commons:

user=> (.length a-string)
7
user=> (.substring a-string 3)
"name"
user=> (.substring a-string 3 5)
"na"

// And for static methods

user=> (def rt (.getRuntime Runtime))
#'user/rt
user=> (.freeMemory rt)
30462304

The beginning of the chapter said In Clojure, strings are the same as Java strings, but not that Clojure uses String from Java, which is a different thing.

So, if my goal is to develop Clojure targeting the browser, what APIs and types can I use? Is there a simple distinction for this? I imagined that anything that doesn't need to be explicitly required (core libs) would be core Clojure and I wouldn't be tying myself the Java libs.

Thank you in advance.

like image 470
bitoiu Avatar asked Dec 04 '25 19:12

bitoiu


1 Answers

If you want to write code to target both Clojure on the JVM and ClojureScript, see cljx.

Without using such tools (to embed code snippets explicitly written for either backend), it is not generally expected that substantial programs will work against both independently.

like image 141
Charles Duffy Avatar answered Dec 08 '25 00:12

Charles Duffy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!