Church numerals: Difference between revisions

m
(→‎{{header|C++}}: tweeks; clean-up)
Line 373:
int main() {
// show some examples
auto zerothree = Successor(Successor(Successor(Zero)));
auto three = Successor(Successor(Successor(zero)));
auto four = Successor(three);
auto six = ToChurch<6>();
Line 384 ⟶ 383:
std::cout << "\n 3^4 = " << ToInt(Exp(three, four));
std::cout << "\n 4^3 = " << ToInt(Exp(four, three));
std::cout << "\n 0^0 = " << ToInt(Exp(zeroZero, zeroZero));
std::cout << "\n 4 - 3 = " << ToInt(Subtract(four, three));
std::cout << "\n 3 - 4 = " << ToInt(Subtract(three, four));
Line 394 ⟶ 393:
 
// calculate the golden ratio by using a Church numeral to
// apply the funtion 'f(x) = 1 + 1/x' a thousand times
std::cout << "\n golden ratio = " <<
thousand([](double x){ return 1.0 + 1.0 / x; })(1.0) << "\n";
}
}</syntaxhighlight>
{{out}}
<pre>
125

edits