The special but important case of compiling clojurescript also raises
some issues.
When clojurescript source code is read, this is done by clojure, and
thus the clojure tag readers apply. Currently they are re-bound to
read the tag literals into clojurescript source code which, when
executed, create the corresponding object.
There are two problems with this
1. you have the definition of the cljs tags in 2 places, 1 in clj
during compile, and 1 in cljs during runtime
2. you have to manually juggle which readers clj should use when (this
can be a real problem for the cljs toolchain)
The root problem is that there is no representation of tagged literals
other than as strings, which is the problem we are trying to solve
here.
Instead of serializing objects directly into eg #inst "2012-01-01" ,
they could first be converted into a GenericLiteral type, and then
appropriately dealt with by the cljs emitter (which will emit code to
resolve the tag name at runtime)
So the procedure for creating user-defined tagged literals could be:
a) implement a function that takes data and returns the constructed
datastructure, b) implement a protocol to generate a GenericLiteral
from the constructed datastructure.
In addition to solving the above problems, it is simpler, easier, and
less error prone than forcing the user to assemble the string
themselves. It is also forward-compatible with more compact binary
representations of clojure data.