[Issue 5660] yield syntax sugar

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jul 29 07:52:02 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=5660


Adam D. Ruppe <destructionator at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |destructionator at gmail.com


--- Comment #8 from Adam D. Ruppe <destructionator at gmail.com> 2012-07-29 07:51:55 PDT ---
// this is your sugar!
string yield(string what) { return `if(auto result = dg(`~what~`)) return
result;`; }


Now, every time you would write

        result = dg(y);
        if (result)
            return result;

instead write:

mixin(yield("y"));

Or mixin(yield("i, y")); if you have multiple arguments.


And the boilerplate is way down. Since you keep result around,
you'll want to make it just if(result) instead of if(auto result),
but the idea is the same.


We might be able to make a class template or a mixn for
yield(int) hanoiTower() too, but writing int opApply(...)
isn't too bad.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list