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

Paul Collier paching at gmail.com
Thu Aug 16 00:43:00 PDT 2007


Robert Fraser wrote:
> 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...).

Cool to see a post about this :)

I was also pondering something similar a while back... D to Javascript 
converter, RPC inserted for you to link up client/server stuff, 
automatic Google Gears integration, all the rest. It's a huge endeavour, 
though--I mean full-stack-web-framework huge. Steve Yegge even mentioned 
something on the topic. Still neat to think about, though :)

Anyways, relating to your post... you'd definitely want to make a 
separate tool using the frontend code to do any of that sort of stuff. 
While you'll quite possibly be able to do a huge amount of introspection 
or whatnot a la Lisp there're bound to be some corner cases where you 
find that the compiler's just not capable yet, or has a bug, or 
something else that'll cause you headaches. There's just too much stuff 
that can trip you up. Besides, while CTFEs are pretty impressive, it's 
much nicer to have a *fully* capable programming environment. And you 
probably don't want to just bloat up the object code with Javascript 
code, etc etc.

Not to discourage you! I truly hope macros would be up to the task too. 
I don't think anyone really knows what they'll be capable of, yet...



More information about the Digitalmars-d mailing list