4 ms·
"Clearly there is no recursion, iteration, or mutation." I don't see how it's clear there is no recursion. Perhaps my definition of recursion is overly broad?
by SteveJS 15y ago
"Clearly there is no recursion, iteration, or mutation."
I don't see how it's clear there is no recursion. Perhaps my definition of recursion is overly broad? I will now proceed to demonstrate my deep ignorance. :-) [edit ... I'm not being sarcastic here ... I suspect I may be wrong on some definition or other.]
Drop the example in a debugger and you can step in until there are 7 instances of the callsite "return ((n == 0) ? 1 : (n*fact(n-1))) ;" on every other frame of the callstack.
I would describe this as the anonymous function in the Ycombinator calls the generator corecursively making a callstack proportional to the number of times you must call the generator before it finds the fixed point.
- walrus 15y agoYour definition of recursion is overly broad. var Y = function (F) { return (function (x) { return F(function (y) { return (x(x))(y);}); }) (function (x) { return F(function (y) { return (x(x))(y);}); }) ; } ; [...] The Y combinator is a closed expression--it makes no explicit reference to an outside variable or to itself. Clearly, there is no recursion, iteration or mutation. Look at the definition of Y—there are no capital Ys after the 5th character (or any equivalent things like arguments.callee).
- SteveJS 15y agoAh ... I misinterpreted the statement to encompass the expression rather then just the application of the Ycombinator. Y(F) is not recursive. (Y(F))(X) is recursive. Is that accurate?