So it's not intended, for example, to use things like ::mygameobject-id on other namespaces of specific 'gameobject' each?
Among the things I'm playing around with is having a ::gameobject-id
defined in some-ns.game
and use that in some-ns.game.dog
and some-ns.game.bat
, each of which has an :id
which is a gameobject-id. Am I doing things in a non-Clojure way?
:: means to auto-resolve the keyword in the context of the current namespace
so if you're using ::id in different namespaces, you'll get different keywords specific to each namespace, and there is no conflicting name
and if I want to use the same spec definition for each? just use a common function?
you can (s/def ::id ::common/gameobject-id)
in each namespace
so have one common spec and then make namespaced specs that refer to it
removing the potentially confusing auto-resolving keywords, something like:
(s/def :common/gameobject-id string?)
(s/def :some-ns.game.dog/id :common/gameobject-id)
(s/def :some-ns.game.bit/id :common/gameobject-id)
I was trying to do just that and it didn't work, and not it works. Great. Maybe I had a funky repl state before :man-shrugging: Thanks!
good!
I see that when I do something like
(s/def ::thingy (s/keys :req-un [:common/gameobject-id]))
Then the thingy gets an :id
property, and not { :common/gameobject-id "whatever" }
Which is good for me
(or maybe :gameobject-id
, I am mixing up some namings between this chat and my actual code)
it doesn't "get" a :gameobject-id property, it describes a map expected to have a :gameobject-id key which matches the :common/gameobject-id spec
I meant that when I conform something to ::thingy, the keyword in the conformed map is { :gameobject-id "something" }
and not { :common/gameobject-id "something" }
. I guess it omits the namespace from the keyword?
:req-un means "required unqualified key"
(as opposed to :req)
so more importantly it's validating the incoming map expecting an unqualified key
conforming just follow that
I seeeee I made a thingy2 now with :req and it wants the fully qualified key
Interesting and cool.
Do I have to require common for using :common/gameobject-id or something?
Oh nevermind.
no