I'm trying to compile the onDispatch demo program from "The D Programming Language" (page 387). At first I had an import problem, but I fixed that. Now, however, when I try to call "a.do_something_cool", I get an error message saying:

onDispatch.d(43): Error: no property 'do_something_cool' for type 'onDispatch.A'

Full program follows (into onDispatch.d):
import core.stdc.ctype;
import std.stdio;

string underscoresToCamelCase(string sym) {
    string result;
    result.reserve(sym.length);
    bool makeUpper;
    foreach (c; sym) {
        if (c == '_') {
            makeUpper = true;
        } else {
            if (makeUpper) {
                result ~= toupper(c);
                makeUpper = false;
            } else {
                result ~= c;
            }
        }
    }
    return result;
}

unittest {
    assert(underscoresToCamelCase("hello_world") == "helloWorld");
    assert(underscoresToCamelCase("_a") == "A");
    assert(underscoresToCamelCase("abc") == "abc");
    assert(underscoresToCamelCase("a_bc_d_") == "aBcD");
}

class A {
    auto onDispatch(string m, Args...)(Args args) {
// return mixin("this."~underscoresToCamelCase(m)~"(args)");
    }

    void doSomethingCool(int x, int y) {
        writeln("Do something cool");
    }
}

unittest {
    auto a = new A;
    a.doSomethingCool(5, 6);
    a.do_something_cool(5, 6);
}

Reply via email to