Name: Anonymous 2011-03-29 16:02
# START HAXING ANII
ops = {'add': '+', 'sub': '-', 'mul': '*', 'div': '/',
'mod': '%', 'pow': '**', 'lshift': '<<',
'rshift': '>>', 'and': '&', 'xor': '^', 'or': '|',
'lt': '<', 'le': '<=', 'eq': '==', 'ne': '!=',
'gt': '>', 'ge': '>='}
form = ''' def __{0}__(self, x):
if isinstance(x, Section):
return lambda y, z: y {1} z
return lambda y: y {1} x
def __r{0}__(self, x): return lambda y: x {1} y'''
defi = ['class Section:']
for k, v in ops.items():
defi.append(form.format(k, v))
exec '\n'.join(defi); _ = Section()
# END HAXING ANII
square = (_ ** 2)
negate = (0 - _)
print square(3), negate(6) # 9, -6
print map(5 * _, [1,4,9,16]) # [5, 20, 45, 80]
print reduce(_ * _, range(1, 10)) # 362880Also, I'll make this compatible with Pipe one day. One word, the forced indentation of Haskell, thread over.