André Thieme <[EMAIL PROTECTED]> writes: > def nif(num, pos, zero, neg): > if num > 0: > return pos > else: > if num == 0: > return zero > else: > return neg
def nif(num, pos, zero, neg): return (neg, zero, pos)[cmp(num, 0)+1] > The messages were printed in each case. > To stop that I need lazy evaluation: > CL-USER> (mapcar #'(lambda (x) > (funcall > (nif x > #'(lambda () (p)) > #'(lambda () (z)) > #'(lambda () (n))))) > '(0 2.5 -8)) in Python: def lazy_nif(num, pos, zero, neg): return (neg, zero, pos)[cmp(num, 0)+1]() # the () at the end means funcall map(lambda x: lazy_nif(x, p, z, n), (0, 2.5, -8)) "nif" is even cleaner in Haskell, if I have this right: nif x p z n | (x < 0) = n | (x == 0) = z | (x > 0) = p All Haskell evaluation is automatically lazy, so no lambdas etc. needed. -- http://mail.python.org/mailman/listinfo/python-list