custom AST library

Alex_Dovhal alex_dovhal at yahoo.com
Tue Dec 21 12:26:00 PST 2010


"Andrej Mitrovic" wrote:
> I'm just having a look at this now, looks rather interesting! I'd love
> to be able to use some Python-like list comprehension tricks in my D
> code.

Yes list comprehension is also possible this way. But it is not very eye 
handy right now even if fully implemented, because one can't use variables 
external to the scope of sum or listcomp... templates, also those 
parenthesis and braces..., so must write:

float a = 1 ;
int n = 10 ;
float x = mixin(sumImpl(q{i=0:10; a*i})) ;
float y = mixin(sumImpl(q{i=1:n; i*mixin(prodImpl(q{j=0:i ; i+j}))}));

instead of:

float a = 1 ;
int n = 10 ;
float x = sum!(q{i=0:10; a*i}) ;
float y = sum!(q{i=1:n; i*prod!(q{j=0:i ; i+j})});

I made it as my first attempt to use D, that's why maybe it's not solid or 
well designed, so any ideas are welcomed. 




More information about the Digitalmars-d mailing list