[Python-Dev] Function Operators (original) (raw)
Christopher Olah christopherolah.co at gmail.com
Sun Jul 18 17:34:46 CEST 2010
- Previous message: [Python-Dev] Windows process creation flags
- Next message: [Python-Dev] Function Operators
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Dear python-dev,
In mathematical notation, fg = z->f(g(z)) and f^n = ff*f... (n times). I often run into situations in python where such operators could result in cleaner code. Eventually, I decided to implement it myself and see how it worked in practice.
However, my intuitive implementation [1] doesn't seem to work. In particular, despite what it says in function's documentation, function does not seem to be in builtin. Furthermore, when I try to implement this through type(f) (where f is a function) I get invalid syntax errors.
I hope I haven't made some trivial error; I'm rather inexperienced as a pythonist.
Christopher Olah
[1] Sketch:
def builtin.function.mul(self, f): return lambda x: self(f(x))
def builtin.function.pow(self, n): return lambda x: reduce(lambda a,b: [f for i in range(n)]+[x])
- Previous message: [Python-Dev] Windows process creation flags
- Next message: [Python-Dev] Function Operators
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]