Nick Sabalausky wrote:
"davidl" <dav...@nospam.org> wrote in message news:op.usje9ia3j5j...@my-tomato...
The benefit is you don't need to write the call function,

...But you do have to write the opDotExp() function. How is that less work than just writing a dispatch function?

It's more work, but it lets you do other interesting things.

Prime example is one I mentioned earlier. Let's say we also get full RTTI implemented soon (either in a library [I'm working on it] or in the compiler). Then you can write a Variant type that you can call arbitrary methods on. Neat, huh?

Let's say you integrate D with a scripting language where you can add methods to an object at arbitrary times. Instead of writing:
scriptObj.invokeMethod("methodname", arguments);

You can instead write:
scriptObj.methodname(arguments);

This is a library type which has no business knowing about any methods that you have defined on scriptObj. Moreover, the alternative is to write this:

template ScriptMethod(string name)
{
enum ScriptMethod = "void " ~ name ~ "(...) { return _vm.invokeMethod(_obj, \"" ~ name ~ \"" ~, _arguments, _argptr); }";
}

class ScriptObjWrapper
{
        // repeat this a few dozen times for each method
        mixin (ScriptMethod!("methodname"));
}



It's syntactic sugar, but it's really neat.

Reply via email to