Timon Gehr wrote:
We have the macro keyword. I envision something like:

macro replaceAggregate(macro newAggregate, macro loop : foreach(x; aggr){statements}, macro x, macro aggr, macro statements) {
    foreach(x; newAggregate){statements}
}

void main(){
    int[] a = [1,2,3];
    int[] b = [2,3,4];
    replaceAggregate(b, foreach(x;a){writeln(x);});
}

(The syntax looks horrible, but you get the idea: AST walking by pattern matching)

This looks substantially more complicated than what I had in mind. I think it's a great idea, but something that could be added after the initial functionality was there.


macro until(macro condition, string str){
    while(!condition){
        mixin(str); // string and mixin not strictly necessary,
// maybe enable the feature on macro params too
    }
}

void main(){
    bool done = false;
    int x;
    until(done){
        done = foo(x++);
    }
}

This is just a very rough sketch though, we would need a much more refined design. I think getting the symbol scoping right is most important.

I'm a bit confused about what's actually going on here, but it certainly looks interesting. What exactly is being passed to "string str" in the macro?

Reply via email to