*defdyn-prefix* (keyword)
*defdyn-prefix* is bound to the keyword :defdyn-prefix—it provides
a global alias to the :defdyn-prefix dynamic binding. When set,
:defdyn-prefix indicates a namespace prefix for bindings created with
defdyn. Its primarily used to prevent name collisions between dynamic
bindings.
repl> (root-env '*defdyn-prefix*)
@{:doc "Optional namespace prefix to add to keywords declared with `defdyn`.\n Use this to prevent keyword collisions between dynamic bindings."
:dyn true
:source-map ("boot.janet" 1333 1)
:value :defdyn-prefix}
Things I Learned
- The dynamic bindings in Janet’s core API often have common, generic names
(e.g.,
:debug,:err,:exit). It would be a shame if those names were “stolen” from module authors due to their privileged use in the core API. Fortunately, Janet doesn’t seem to reserve much privilege for its own implementation. Namespacing solves this particular problem gracefully. - The namespace prefix applies only to the dynamic binding’s keyword in
the environment table. Because the alias name created by
defdynis not affected, module authors can use a succinct name in the API and a name with minimal odds of collision for the underlying keyword. This is another good reason to prefer use of the dynamic binding alias rather than the keyword when accessing dynamic bindings.