repo.or.cz
/
mozilla-central.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git]
/
js
/
src
/
Y.js
blob
e92a65a5df977952002fe7b3186d94d3acfb6b41
1
// The Y combinator, applied to the factorial function
2
3
function
factorial
(
proc
) {
4
return function
(
n
) {
5
return
(
n
<=
1
) ?
1
:
n
*
proc
(
n
-
1
);
6
}
7
}
8
9
function
Y
(
outer
) {
10
function
inner
(
proc
) {
11
function
apply
(
arg
) {
12
return
proc
(
proc
)(
arg
);
13
}
14
return
outer
(
apply
);
15
}
16
return
inner
(
inner
);
17
}
18
19
print
(
"5! is "
+
Y
(
factorial
)(
5
));