4 ms·
Y combinator in JavaScript: http://thraxil.org/users/anders/posts/2008/09/15/My-Own-Javascript-Y-Combinator/ http://thraxil.org/users/anders/posts/2008/09/15/My
by caustic 18y ago
Y combinator in JavaScript: http://thraxil.org/users/anders/posts/2008/09/15/My-Own-Javascript-Y-Combinator/ http://thraxil.org/users/anders/posts/2008/09/15/My-Own-Java...
- zmimon 18y agoI'm not very literate in functional programming ... so excuse such a dumb question. But I'm curious why you write the recursing function duplicated? eg. isn't this version of your code equivalent? function Y(X) { var fn = function(procedure) { return X(function(arg) { return procedure(procedure)(arg); }); }; return fn(fn); } Or am I missing something vital here about how it is all working? The shorter version seems clearer to me (not that any of this is clear to me), and functionally equivalent.
- Avshalom 18y agothe duplication is to allow it to be anonymous. Your version names a function.