# 查看完整版本 : Y combinator

xianrenb 2017-12-9 01:53 PM

## Y combinator

[url=https://en.wikipedia.org/wiki/Fixed-point_combinator]https://en.wikipedia.org/wiki/Fixed-point_combinator[/url]

[url=http://rosettacode.org/wiki/Y_combinator#JavaScript]http://rosettacode.org/wiki/Y_combinator#JavaScript[/url][code]var fac = Y(function(f) {
return function (n) {
return n > 1 ? n * f(n - 1) : 1;
};
});[/code]但呢次見到 [url]http://snap.berkeley.edu/[/url] 有個 y combinator example ：

d project d code 好複雜，反而讓人感覺一點也不好玩。

Susan﹏汪汪 2017-12-9 02:06 PM

Fixed-point combinator係用來寫recursive function

[[i] 本帖最後由 Susan﹏汪汪 於 2017-12-9 02:19 PM 編輯 [/i]]

Susan﹏汪汪 2017-12-9 02:27 PM

[code]var fac = Y(function(f) {
return function (n) {
return n > 1 ? n * f(n - 1) : 1;
};
});[/code]

xianrenb 2017-12-9 02:32 PM

[quote]原帖由 [i]Susan﹏汪汪[/i] 於 2017-12-9 02:06 PM 發表 [url=http://computer.discuss.com.hk/redirect.php?goto=findpost&pid=472133864&ptid=27111425][img]http://computer.discuss.com.hk/images/common/back.gif[/img][/url]

Fixed-point combinator係用來寫recursive function [/quote]

[url=https://en.wikipedia.org/wiki/Fixed-point_combinator]https://en.wikipedia.org/wiki/Fixed-point_combinator[/url]
[quote]...In the lambda calculus it is not possible to refer to the definition of a function in a function body. Recursion may only be achieved by passing in a function as a parameter....[/quote]

[[i] 本帖最後由 xianrenb 於 2017-12-9 02:34 PM 編輯 [/i]]

Susan﹏汪汪 2017-12-9 02:39 PM

[quote]原帖由 [i]xianrenb[/i] 於 2017-12-9 02:32 PM 發表 [url=http://www.discuss.com.hk/redirect.php?goto=findpost&pid=472134878&ptid=27111425][img]http://www.discuss.com.hk/images/common/back.gif[/img][/url]

https://en.wikipedia.org/wiki/Fixed-point_combinator