Thanks for these ideas. Alas both seem somewhat hacky, I was hoping for
something more established. Also, both require modifying each occurrence of a
symbol and/or don't work for every kind of symbol.
I might have over-generalized my question in the hope of getting a general
answer. If namespaces are mostly considered useless in Nim, I don't see the
point of emulating namespaces in a unconventional way. That would only add
confusion and only few of the benefits I was looking for.
My question was originally based on one particular situation, which in other
languages would have been solvable with namespaces and their manipulation. What
would be the nim-as-intended way to solve this?
# stable.nim
# symbols that also exist in the other subpackage
proc hello*() = echo "hello"
# symbols that currently only exist in this subpackage
proc yetAnotherHello*() = echo "whats up"
Run
# experimental.nim
# symbols that also exist in the other subpackage
proc hello*() = echo "hi"
# symbols that currently only exist in this subpackage
proc alternateHello*() = echo "heyho"
Run
# package.nim
import stable
import experimental
export stable
export experimental
Run
# usingPackage.nim
import package
stable.hello()
experimental.hello()
alternateHello() # from experimental
yetAnotherHello() # from stable
Run
Assume I can only change `package.nim`, the other files could well be written
by someone else (and have other priorities than catering to my situation).
My issues with the code are:
1. How to nudge users to use the `stable` subpackage and make this more
common usage easier by implying the namespace `stable`? Currently, all
duplicated symbols require the subpackage's namespace.
2. `usingPackage.nim` breaks quite badly when a future update adds either
`alternateHello` to `stable` or `yetAnotherHello` to `experimental`. One
approach would be to require the `experimental` namespace even when not
shadowed by a symbol from another subpackage.