update: I have raised this as an issue: https://clojure.atlassian.net/jira/software/c/projects/CLJS/issues/CLJS-3294
I am trying to write a library which provides a set of tagged literals (and their reader fns) for consumption from both clojure and clojurescript.
data_readers.cljc
{foo/bar my.project.foo/bar}
my/project/foo.cljc
(ns my.project.foo)
(defn bar [x]
#?(:clj (str "hello! " x)
:cljs (clj->js x)))
cmd line:
clj --main cljs.main -e "(println #foo/bar \"world\")"
prints "hello, world"
clojurescript compiles+executes the :clj branch in the bar reader fn - as far as I can see there is no way to execute cljs code in a reader. I have also tried having a my/project/foo.cljs
(ie cljs only) file - but this doesn't work either.
I have tried using a workaround where the reader function returns a form, see https://github.com/henryw374/time-literals/blob/master/src/time_literals/data_readers.cljc and this works ok, except that now those reader functions don't work when being used with clojure (e.g. clojure.core/read-string) - see https://github.com/henryw374/time-literals/issues/3
Thanks,
Henry