DIP 50 - AST macros
deadalnix
deadalnix at gmail.com
Tue Nov 12 12:36:34 PST 2013
On Tuesday, 12 November 2013 at 17:20:20 UTC, Andrei Alexandrescu
wrote:
>> As I have already mentioned, it is the
>> very same thing we do now with __traits and UDA's but not
>> limited to
>> only declarations.
>
> Interesting.
>
The thing I'd like to be able to do it to create a
async/await/yield like mechanism, purely as library.
@generator
uint foo() {
writeln("generating !");
return 0;
return 1;
writeln("and the last one");
return 2;
}
=>
auto foo() {
enum States {
S0,
S1,
S2,
}
struct Generator {
State s;
uint current;
@property front() {
return current;
}
void popFront() {
final switch(s) with(State) {
case S0:
current = 1;
s = S1;
return;
case S1:
writeln("and the last one");
current = 2;
s = S2;
return;
case S2:
assert(0, "Nothing more in here");
}
}
@property empty() {
return s == State.S2;
}
}
auto g = Generator();
writeln("generating !");
g.current = 0;
g.state = State.S0;
return g;
}
More information about the Digitalmars-d
mailing list