Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Tail-recursions are the exact equivalent of loops.

Not necessarily. In the common case of a procedure calling itself a loop does wind up being equivalent. OTOH with mutually recursive procedures (two or more procedures which call each other), there is no straightforward way to convert the tail calls into a loop.



Is there any reason why something like the following should not work?

    while (condition)
    {
        a();
        if (!condition)
            break;
        b();
    }


Your example assumes that you can inline the calls to a and b. If you can't (for example if one of them calls themselves) then your optimization won't work.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: