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

Kinda-sorta:

    function psuedoduff(count) {
        var x = 0;
        var n = Math.floor((count + 7) / 8);
        var o = {
            0: function() { x++; o[7]() },
            7: function() { x++; o[6]() },
            6: function() { x++; o[5]() },
            5: function() { x++; o[4]() },
            4: function() { x++; o[3]() },
            3: function() { x++; o[2]() },
            2: function() { x++; o[1]() },
            1: function() { x++; n--; if (n > 0) { o[0]() }},
        }

        if (count > 0) {
            o[count%8]();
        }

        return x;
    }
That just increments to show the point, it would be easy to make it do some sort of real work.

Of course you'll run out of recursion at some point. Trampolining could fix that. I leave it as an exercise for the reader whether that makes it more or less silly.

I'm also of course aware that Duff's device doesn't make function calls, to which I vigorously handwave while chanting "Monads Are Programmable Semicolons" in my "Lambda The Ultimate" T-Shirt.

Lambda.



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

Search: