[Issue 5140] Add __FUNCTION__

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Oct 31 05:57:56 PDT 2010


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


bearophile_hugs at eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs at eml.cc


--- Comment #1 from bearophile_hugs at eml.cc 2010-10-31 05:56:56 PDT ---
It also allows code like this, this recursive code will keep working even if
"fact" gets renamed, it's more DRY:


long fact(long n) {
    if (n <= 1)
        return 1;
    else
        mixin("return n * " ~ __FUNCTION__ ~ "(n - 1);");
}
void main() {
    assert(fact(20) == 2_432_902_008_176_640_000);
}


But an alias of the current function is more handy for that purpose:

long fact(long n) {
    if (n <= 1)
        return 1;
    else
        return n * __function(n - 1);
}
void main() {
    assert(fact(20) == 2_432_902_008_176_640_000);
}

-- 
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