how to avoid "cycle detected"?

aki via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 2 22:19:15 PDT 2015


On Thursday, 2 July 2015 at 17:21:03 UTC, Kapps wrote:
> An ugly solution, but the approach used in Phobos is to create 
> something like a_init.d which a.d imports, provided that the 
> static ctors don't actually rely on things from the static ctor 
> of b.

How about this idea?
Allowing to define sub module in a module.

file foo.d:
module foo;

// nameless module, automatically imported by outer module foo
module {
	int[] needInitialize;
	static this() { needInitialize = ...; }
}
// use statically initialized variable needInitialize...

Basically, d-lang's module has one-to-one correspondence with 
file.
This new feature breaks this rule, but it's safe because
this one is private to module foo.
There are no way to import this nameless module by other modules.
The purpose is just the alternative to making foo_init.d file.

aki.



More information about the Digitalmars-d-learn mailing list