AST Macros: Just what will they be able to do?

Robert Fraser fraserofthenight at gmail.com
Wed Aug 15 19:20:29 PDT 2007


On my bus ride this morning, I was thinking about how to make web 2.0 programming more like desktop GUI programming, and I came up with an idea that's probably been come up with many times before: what if the entire website could be designed programmatically, similarly to .NET forms or something? In particular, I was thinking "what if callbacks could somehow be parsed into client and server-side components automatically?" I think an example is necessary here, so lets' say the coder has two checkboxes -- cb1 and cb2. They are D objects when the website is being created by the servlet, that render as <input type="checkbox"> or whatever. Now say the coder writes this:

cb1.onChange = {
    if(cb1.enabled)
        cb2.enabled = true;
    else
        cb2.enabled = false;
}

cb2.onChange = {
    if(cb2.enabled)
        doSomethingOnTheServer();
}

Using AST macros, would there be any way for the program to figure out at compile-time cb1s callback could be done entirely on the client side via JavaScript or something while cb2's would require some AJAX calls in some cases (which would then be generated automatically)? In particular, it would need to know that everything within the callback for cb1 refers to variables/state within a particular set those which are available on the client).

So, what's the chance that AST macros would have this power? I think it'd make writing web interfaces a lot more interesting... Of course, I'd still need to figure out how to transform the D code to JavaScript, but I'm sure a little CTFE magic will help out with that (time to port that DMDFE to CTFE...).



More information about the Digitalmars-d mailing list