def compile_function(self): """Called in set_value to compile into a function.""" if self.value.count_nodes() > self.maxnodes: return lambda *args: raise_exception(TooBigException) else: try: return eval(str(self)) # evaluate_expression(str(self)) except Exception as e: print "# Warning: failed to execute evaluate_expression on " + str(self) print "# ", e return lambda *args: raise_exception(EvaluationException)
def compile_function(self): """Called in set_value to compile into a function.""" if self.value.count_nodes() > self.maxnodes: return lambda *args: raise_exception(TooBigException) else: try: return eval(str(self)) # evaluate_expression(str(self)) except Exception as e: print "# Warning: failed to execute evaluate_expression on " + str( self) print "# ", e return lambda *args: raise_exception(EvaluationException)
def Y_bounded(f): """ A fancy fixed point iterator that only goes MAX_RECURSION deep, else throwing a a RecusionDepthException """ return (lambda x, n: x(x, n))( lambda y, n: f(lambda *args: y(y, n + 1)(*args)) if n < MAX_RECURSION else raise_exception(RecursionDepthException), 0)
def Y_bounded(f): """ A fancy fixed point iterator that only goes MAX_RECURSION deep, else throwing a a RecusionDepthException """ return (lambda x, n: x(x, n))(lambda y, n: f(lambda *args: y(y, n+1)(*args)) if n < MAX_RECURSION else raise_exception(RecursionDepthException), 0)