On Tuesday, 11 July 2017 at 17:20:33 UTC, Ali Çehreli wrote:

That's some serious code you've written there and you must be happy that 'virtual' is not a keyword in D. ;)

Thanks. Haha I would have used virtual_ like I did in C++ ;-)

Maybe others can come up with ideas on a better syntax.

When it is presentable (I'm almost there) I plan to ask a review. I would welcome suggestions about the syntax - which is not too bad as it is now, I have been happily surprised with what is feasible. It even supports overloading methods.

The thing that annoys me most is having to pass a string to 'method'. And attributes are not allowed on arguments. I wish I would make something like this work:

mixin method!(fight, string, virtual!Character, virtual!Creature, virtual!Device);

    // or:
mixin method!(fight, string, @virtual Character, @virtual Creature, @virtual Device);

    // even better
mixin method!(fight, function string(@virtual Character, @virtual Creature, @virtual Device));

    // and if there is a catch-all implementation:
mixin method!(fight, function string(@virtual Character, @virtual Creature, @virtual Device) {
        // body
    }

I tried to get inspiration from Yes and No, considered using opDispatch, but I haven't found a way yet.

Just to get the conversation going and without thinking it through, how about something like the following?

struct Virtual(Args...) {
    // ...
}

@Virtual("t", "d", "w")
string fight(Character t, Dragon d, Hands w) {
return "you just killed a dragon with your bare hands. Incredible isn't it?";
}

The 'virtual' qualifier applies to the arguments in the method declaration, not the specializations. Also, I prefer to keep the qualifiers stuck to the argument. It's clearer. Interesting idea though.

Then, something like the following which would parse the module to do its magic:

mixin ProcessMethods();

Very interesting. I don't like the repetition of 'mixin' in front of each 'method' and 'implementation'.

Hmmm...if ProcessMethods() can find @Virtual(...) functions can't it find functions that have virtual! parameters?

Reply via email to