Hi! There's an `if-cljs` macro implemented and used in some libraries, for example in Prismatic/schema (it's cljx, but I think it still applies https://github.com/plumatic/schema/blob/c6b66316231b9c8164b6a8580389c7584091de88/src/clj/schema/macros.clj#L15) and tonsky/datascript (https://github.com/tonsky/datascript/blob/e52ee66a332820137a14c8fa8eb47e9357f1b93a/src/datascript/arrays.cljc#L8-L25). You could try with that approach. There's an old thread where it is discussed (https://groups.google.com/forum/#!topic/clojurescript/iBY5HaQda4A) and I also wrote about it at the end of http://blog.nberger.com.ar/blog/2015/09/18/more-portable-complex-macro-musing/ where I also analyze other approaches that didn't work for me.
Another comment that might help is that in clojurescript you can only have 1 `:require` in a `ns` form, so in clojure.core.matrix.compliance-tester only the 2nd require (the require of cljs.test) is taken into account, yielding the "No such namespace: mat, could not locate mat.cljs..." warnings. I pushed a branch which includes some of this changes and other minor stuff in https://github.com/nberger/core.matrix/tree/if-cljs. Feel free to cherry pick anything from there, but please take into account that I'm not sure if it works, because I couldn't run the tests. Good luck with the port, you are almost there!! On Sat, Jan 16, 2016 at 7:30 PM, <[email protected]> wrote: > Hi Clojurescripters, > > I've been chipping away on core.matrix support for Clojurescript, but I > could use some help figuring out some final macro issues that are breaking > the unit tests and driving me nuts. > > For anyone motivated, we've got a cljc branch here: > > https://github.com/thinktopic/core.matrix/tree/cljc > > which is using the matrix branch of the ndarray library for cljs here: > > https://github.com/thinktopic/ndarray/tree/matrix > > > In short, I think the problem is that there are a few macros which need to > differ between Clojure and Clojurescript. Here are two examples from > clojure.core.matrix.macros.cljc: > > > (defmacro error > "Throws an error with the provided message(s)" > ([& vals] > `(throw (#? (:clj RuntimeException. > :cljs js/Error.) > (str ~@vals))))) > > (defmacro error? > "Returns true if executing body throws an error, false otherwise." > ([& body] > `(try > ~@body > false > (catch #?(:clj Throwable :cljs js/Error) t# > true)))) > > > What I'm unclear about is how conditional compilation works in such > situations. By definition macros are in Clojure, but I need to have > different versions of the macro compile for clj and cljs. When I try to > build cljc files that refer to these macros I get errors, that either they > don't exist, or that js/Error is an invalid java class. How should such > situations be handled? > > Thanks, > Jeff > > P.S. The good news is: it works! We can matrix multiply core.matrix arrays > in the browser. Lots of very cool stuff to follow, but I need to get the > tests passing to get these changes merged upstream. > > -- > Note that posts from new members are moderated - please be patient with your > first post. > --- > You received this message because you are subscribed to the Google Groups > "ClojureScript" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/clojurescript. -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/clojurescript.
