Hacker News new | past | comments | ask | show | jobs | submit login

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/plumatic/schema (uses .cljx, the precursor to .cljc)




Nice 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?


The first part requires platform on both platforms. You are correct about the latter.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: