To make a URI into a Clojure keyword namespace, we may simply replace
the 11 URI characters that are forbidden or problematic in keywords
with Unicode-alphabetic characters outside Latin-1.
The substitutes should be present in common desktop fonts, and should
not be mistaken for Latin-1 characters. They should come from a
single Unicode script, to avoid burdensome Unicode puns. It should
be a raster script that does not require decades of handwriting practice.
Cyrillic fits the bill very well: it's recognizable and out-of-band. You'd
never type these URI keywords in, but Cyrillic is a software-selectable
keyboard so you could if you felt like it.
http://www.cs.yale.edu/~perlis-alan/quotes.html
httpцЛЛwwwЯcsЯyaleЯeduЛжperlis-alanЛquotesЯhtml
Here is a demonstration of a simple URI <-> keyword translator
and a keyword-namespace aliasing macro to facilitate relatively
painless use of namespace literals in source code.
(To furthermore overcome the problem that "%" hex expressions compare
case-blind in URIs, but not keywords, we should norm %xx to %XX as RFC
3986 recommends before converting to a keyword namespace.)
(def problems [\. \~ \: \/ \[ \] \@ \( \) \, \;])
(def solutions [\Я \ж \ц \Л \П \Ю \Ж \ъ \Ъ \г \д])
(defn- tr [a b]
(let [m (zipmap a b)]
(fn [s]
(apply str (map #(m % %) s)))))
(def uri->kwns
(tr problems solutions))
(def kwns->uri
(tr solutions problems))
(defmacro alias-xml-ns [sym uri]
`(let [kwns# (symbol (uri->kwns ~uri))]
(create-ns kwns#)
(alias ~sym kwns#)))
(comment
(uri->kwns "http://www.w3.org/2000/01/rdf-schema#")
(kwns->uri *1)
(alias-xml-ns 'html "http://www.w3.org/1999/xhtml")
(assert
(identical? ::html/aside
:httpцЛЛwwwЯw3ЯorgЛ1999Лxhtml/aside))
)