Live data from Hacker News

The Y combinator in Javascript

matt.might.net

1–10 of 22 posts

Re: The Y combinator in Javascript

#6
post #2

Curiously enough, the JavaScript Y combinator is in the Firefox source and has been since at least 2007: http://hg.mozilla.org/mozilla-central/file/fc78ee766770/js/s...

That is by far the clearest implementation of the Y-combinator I've ever seen. And I'm not even a JavaScript programmer.

Re: The Y combinator in Javascript

#8
post #6
post #2

Curiously enough, the JavaScript Y combinator is in the Firefox source and has been since at least 2007: http://hg.mozilla.org/mozilla-central/file/fc78ee766770/js/s...

That is by far the clearest implementation of the Y-combinator I've ever seen. And I'm not even a JavaScript programmer.

Really? What about

    function Y(f) {
        var g = f(function(arg) {
            return g(arg);
        });
        return g;
    }
The inner() function from Mozilla's implementation is actually unnecessary in languages that support lexical closures.

Re: The Y combinator in Javascript

#9
it looks like all the magic happens with the U combinator, where "recursion" is avoided by finding F = f(f), and passing f as a parameter such that F can be reconstructed.

which still smells like recursion, a type of recursion where the recursive element keeps getting punted around as a parameter like an epileptic cannibalistic stem-cell with no name.

Post reply on HN