by pjc50 · 8y ago · 0 comments
constexpr double delta = 1.0e-6;
constexpr auto deriv = [] (auto f) {
return [=] (double x) {
return (f(x+delta) - f(x)) / delta;
};
};
constexpr auto f¨ = [] (auto f) { return deriv(deriv(f)); };
double res = f¨([] (double x) { return x*x*x; })(2.0);I find that it follows the functional spec quite closely, thanks to Go functions being first class citizens.