3 ms·
There's cljc which is a conditional reader that lets you code in clj and cljs in the same file. It's not that difficult to write a library that runs on both.
by 147 11y ago
There's cljc which is a conditional reader that lets you code in clj and cljs in the same file.
It's not that difficult to write a library that runs on both.
But there are differences in the runtimes, of course.
Some examples:
https://github.com/stuartsierra/component https://github.com/stuartsierra/component
https://github.com/plumatic/schema https://github.com/plumatic/schema (uses .cljx, the precursor to .cljc)
- jfaucett 11y agoNice examples. Am I correct in guessing that this code: (ns com.stuartsierra.component (:require [com.stuartsierra.dependency :as dep] [com.stuartsierra.component.platform :as platform])) requires the correct platform.clj or platform.cljs depending on the runtime? And that this: #?(:clj (defmethod clojure.core/print-method SystemMap [system ^java.io.Writer writer] (.write writer "#<SystemMap>")) :cljs (extend-protocol IPrintWithWriter SystemMap (-pr-writer [this writer opts] (-write writer "#<SystemMap>")))) is how you perform different operations in a single file based on runtime?
- 147 11y agoThe first part requires platform on both platforms. You are correct about the latter.