Why Ruby?
Adam D. Ruppe
destructionator at gmail.com
Sun Dec 12 19:23:31 PST 2010
Ary Borenszweig wrote:
> D should provide a yield keyword that basically
> rewrites the body of the method into the first code.
Don't need to change the language for that.
=========
string yield(string what) {
return `if(auto result = dg(`~what~`)) return result;`;
}
class Foo
{
uint array[2];
int opApply(int delegate(ref uint) dg) {
mixin(yield("array[0]"));
mixin(yield("array[1]"));
return 0;
}
}
=========
Compiles and runs as expected, on today's D.
More information about the Digitalmars-d
mailing list