emezeske/lein-cljsbuild — Issue #49: Handling Clojure/ClojureScript protocol differences and other platform discrepencies
Author: lynaghk
Created: 2012-03-06 07:02:38+00:00
State: open

How should we handle language runtime and platform between Clojure and ClojureScript?

One option for handling platform differences is to duplicate namespaces across clj and cljs.
In `maths.cljs`:

(ns maths)
(def sqrt (.-sqrt js/Math))

and in `maths.clj`

(ns maths) ;;maths.clj
(defn sqrt [x] (Math/sqrt x))

Then use Clojure as usual and in ClojureScript just let the cljs version of the namespace get picked up (don't list `maths` in the crossovers).

That feels like a lot of unnecessary juggling for a LISP though; perhaps we should take advantage of metadata to mark platform-specific functions and provide alternatives all in the same file?

I've also run into problems with differences in the language runtimes.
For instance, in Clojure:

(reify
clojure.lang.ILookup (valAt [k v] ...))

but in ClojureScript:

(reify
ILookup (-lookup [k v] ...))

Is there anything we can do to crossover Clojure code like this automatically within lein-cljsbuild?
It's probably easier to make the changes in ClojureScript itself, but maybe there is a reason ClojureScript's protocols have slightly different names than Clojure's (pinging @dnolan).