Hi,
As a learning exercise I am implementing some algorithms from Knuth's volume 4B
in Nim. Specifically, I am working through his chapter on the "dancing links"
algorithm for exact cover problems.
There are several variants of this algorithm and they have slightly different
underlying datatypes. I would like to be able to import a common datatypes
module into various algorithm implementation modules and have the imported
datatypes (and some other support code) vary as needed. That is, something like
this:
# In module D, the datatypes:
when defined(it_is_for_algo_1):
type
# ...
elif defined(it_is_for_algo_2):
type
# ...
# etc..
# In module A1
const it_is_for_algo_1* = 1
import D
# In module A2
const it_is_for_algo_2* = 1
import D
Run
I have tried this but module D doesn't see the it_is_for_algo_X consts,
presumably because D doesn't import A1 and A2.
Is there a way to make this happen? I guess I could include instead of import,
but I have some data hiding in the D module that I'd prefer to keep.
Alternatively I could handle this at build time since algo 1 and algo 2 will be
separate binaries. I could manually put "-d:it_is_for_algo{1,2}" on the command
line when building them but want to avoid this. I am using "nimble build" to
build. Can I specify binary-specific defines for the nimble build process? I'd
prefer not to have to go back to using make.