Variadic fixed-point combinator: Difference between revisions

Content added Content deleted
(Have removed my own post as I misunderstood the task.)
Tag: Manual revert
(New post.)
Line 131:
{{out}}
<code>[0,1,2,0,1,2,0,1,2,0,1]</code>
 
=={{header|Java}}==
<syntaxhighlight lang="java">
public final class VariadicFixedPointCombinator {
public interface CompletedFunction {
boolean f(int x);
}
public interface FunctionFixed {
CompletedFunction g();
}
public interface FunctionToBeFixed {
CompletedFunction h(FunctionFixed[] functionFixed);
static FunctionFixed[] k(FunctionToBeFixed[] functionToBeFixed) {
return new FunctionFixed[] { () -> functionToBeFixed[0].h(k(functionToBeFixed)),
() -> functionToBeFixed[1].h(k(functionToBeFixed)) };
}
}
 
public static void main(String[] args) {
FunctionToBeFixed[] evenOddFix = {
functions -> n -> n == 0 ? true : functions[1].g().f(n - 1),
functions -> n -> n == 0 ? false : functions[0].g().f(n - 1)
};
FunctionFixed[] evenOdd = FunctionToBeFixed.k(evenOddFix);
CompletedFunction even = evenOdd[0].g();
CompletedFunction odd = evenOdd[1].g();
for ( int i = 0; i <= 9; i++ ) {
System.out.println(i + ": Even: " + even.f(i) + ", Odd: " + odd.f(i));
}
}
}
</syntaxhighlight>
{{ out }}
<pre>
0: Even: true, Odd: false
1: Even: false, Odd: true
2: Even: true, Odd: false
3: Even: false, Odd: true
4: Even: true, Odd: false
5: Even: false, Odd: true
6: Even: true, Odd: false
7: Even: false, Odd: true
8: Even: true, Odd: false
9: Even: false, Odd: true
</pre>
 
=={{header|Julia}}==