I’m hoping that someone here might know a good solution or tell me I’m wrong, but otherwise here goes for a conversation starter:
Namespaced keywords seem like a great idea in theory, but are not portable (not even within Clojure). Current working example: I have a map representing a student registration. Now, what I’d like to have is this:
{:student/id "23457y89i"
:proctor/id "3"
:language/native "English"
:language/test "Spanish"
;; and so on
}
However, I run in to two problems: first, this is being submitted by a web front-end as json, so I can’t expect keywords to survive the trip intact. Second, even within clojure apps, destructuring with ns keys seems problematic:
{:keys [student/id proctor/id] ;; breaks or results in just one var `id, because namespacing on symbols isn't as virtual as namespacing on keywords
If I’m lucky someone can tell me why I’m wrong, or at least offer a different solution than getting into the habit of structuring my maps as if ns keywords don’t exist:
:keys is a shortcut that probably isn’t meant for what you’re trying to do. You can always use the “longer” form of map destructuring. You’re going to have to specify renames for the keys anyway if you’re going to use them in the same scope.
In the past, I’ve seen a DSL for dealing with Json. I don’t know if there are any high quality libraries. I don’t think I could tell. I don’t have much Json experience. You might try searching for something like that.
I’d consider splitting handling up into two functions, where each function destructures the keys it requires. This sounds like a case for separation of concerns.