On Tuesday, 30 July 2013 at 11:19:37 UTC, Dicebot wrote:
On Tuesday, 30 July 2013 at 11:01:07 UTC, JS wrote:
On Tuesday, 30 July 2013 at 10:36:15 UTC, Dicebot wrote:
You can use scoped local imports and avoid necessity to track global state.

Huh? If I follow you, this won't work. I'm generating code so don't have the luxury to mess with the outer scope where the code is going.

mixin(code fragment)

user code

mixin(code fragment)

user code

if both code fragments have the same import statement then there is an error. The only way for them to be aware of that is to have a global state(well, relative to the scope they are in).

Don't have imports generated in two different mixins in same scope. Either move each mixin into own scope, or move import generation code into separate mixin that get called once per scope. (example of vibe.d using latter: https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/http/rest.d#L245)

This can't be done. I am using mixins to generate interface code,
class code, etc....

There is only one scope to them. The imports can't be brought out
because they are generated directly from the mixin data passed.

e.g.,

class A
{
    mixin(Property("name", string));
    mixin(Property("x", iObject));
}

iObject potentially requires an import, so I import it... now if
I add


    mixin(Property("y", iObject));

then I'll have two iObjects imported... which will error and
fail, even though there is no big deal about it.

Reply via email to