On Wednesday, 26 October 2016 at 09:53:35 UTC, Jeff Thompson wrote:


var Utils1 = require('commit_b3bf5c7/utils.js').Utils;
var Utils2 = require('commit_df0741a/utils.js').Utils;

That works because require operates in terms of files, not modules. In D, module and package names may have a default relationship with the file system, but the modules and packages themselves are wholly constructs of the compiler. `import foo` knows nothing about any files called foo. You need a way for the commit_* directories to become a part of the package name so that you can have distinct namespaces and avoid symbol clashes. If you can make that happen, then you can do this:

import Utils1 = commit_b3bf5c7.utils;
import Utils2 = commit_df0741a.utils;

You also might be able to generate something at compile time with string imports and string mixins.

But really, statically compiled languages aren't fit for this sort of thing. If you can compiled the version-sensitive bits into shared libraries, define a common interface in the main program, then load the libraries manually at runtime... that's the only reasonable way I know of to handle something like this. You could have multiple versions of the interface implementations loaded without issue. But I don't believe D's shared library support is fully implemented across all platforms at the moment.

Reply via email to