[Edu-sig] The Great Computer Language Shootout
Luby Liao
liao@sandiego.edu
Sun, 3 Jun 2001 10:17:13 -0700 (PDT)
Kirby,
> >2. ocaml is very promising language:
>
> agreed.
>
> in caml interactive you can write a function to compose
> two functions, i.e. build r(x) from f(g(x)) or g(f(x)).
>
> #let compose f g = function x -> f(g(x));;
> val compose : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b = <fun>
>
> #let cos2 = compose square cos;;
> val cos2 : float -> float = <fun>
>
> Drawing a blank this AM re how to do this in Python, trying
> various things with little lambda.
>
> Clues?
How about:
def compose(f,g):
global _f, _g
_f = f
_g = g
return lambda x: _f(_g(x))
if __name__ == '__main__':
from math import *
print compose(sin, sqrt)(3)
print sin(sqrt(3))
0.98702664499
0.98702664499
cheers, Luby