Entry
Caml-like functions in Python
Jul 5th, 2000 10:03
Nathan Wallace, Hans Nowak, Snippet 310, Python Snippet Support Team
"""
Packages: maths
"""
# caml.py
"""Some Caml-like functions for Python."""
# A derivative function.
def _deriv(f, x, dx):
return (f(x+dx) - f(x)) / dx
def deriv(f, dx):
return lambda x, f=f, dx=dx: _deriv(f, x, dx)
# Compose a function from two others.
def compose(f, g):
return lambda x, f=f, g=g: f(g(x))
if __name__ == "__main__":
from math import *
def square(x): return x * x
cos2 = compose(cos, square)
print cos2(45)
cosh = deriv(sin, 1e-6)
print cosh(pi)