Name: Anonymous 2007-04-04 9:44 ID:HirEo2Uj
import operator
def Eval(l):
if type(l) == list:
if not l:
return None
else:
return Eval(l[0])(*l[1:])
else:
return l
#Decorator to evaluate arguments; they default to lazy evaluation
evalargs = lambda f: lambda *a: f(*map(Eval, a))
add = evalargs(lambda *a: reduce(operator.add, a))
def eq(*a):
l = len(a)
if l < 2:
return True
o = Eval(a[0])
for i in xrange(1, l):
if Eval(a[i]) != o:
return False
return True
def If(cond, t, f):
if Eval(cond): return Eval(t)
else: return Eval(f)
def Do(*a):
for i in a:
out = Eval(i)
return out
#Maybe also Do = lambda *a: map(Eval, a)[-1], but less efficient
@evalargs
def OutLn(*a):
print u''.join(unicode(i) for i in a)
#Ok, now let's test it:
body = [If, [eq, 1, 1], [OutLn, 10], [OutLn, 20]]
Eval(body)
#Expected: prints 10Do you think I've fapped enough, or should I fap further into this?