Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to distinguish between Clojure-JVM and Clojure-CLR

Tags:

clojure

How can I detect within a clojure-lang script file whether the script is run on JVM version or CLR version?

Thanks in advance.

like image 878
javacommons Avatar asked Feb 25 '19 15:02

javacommons


1 Answers

The tool to use here, are reader conditions: https://clojure.org/guides/reader_conditionals

... Reader conditionals are integrated into the Clojure reader, and don’t require any extra tooling beyond Clojure 1.7 or greater. To use reader conditionals, all you need is for your file to have a .cljc extension and to use Clojure 1.7 or ClojureScript 0.0-3196 or higher ...

... The standard reader conditional behaves similarly to a traditional cond. The syntax for usage is #? and looks like:

#?(:clj  (Clojure expression)
   :cljs (ClojureScript expression)
   :cljr (Clojure CLR expression)
   :default (fallthrough expression))
like image 182
cfrick Avatar answered Nov 09 '22 02:11

cfrick