def eval(self, env, *arg_values): if len(self.arg_labels) != len(arg_values): raise Exception("number of labels (%r, %s) and values (%r, %s) does not match when calling %s" % (len(self.arg_labels), self.arg_labels, len(arg_values), arg_values, self)) return let_t.eval( env, base.tuple( [base.tuple([self.arg_labels[i], arg_values[i]]) for i in xrange(len(self.arg_labels))]), *self.exprs)
def with_env(): # def with_flattened_env(flat): # TODO: only want the values in var_list, not env() # Actually, only want those values that will be used in the lambda....but the var_list should work for now # Not sure if the outer scope applies the same to lambdas in the spec # key = str(base.tuple([base.tuple([base.tuple([name, value]) for name, value in flat.items()]), base.tuple(exprs)])) # print "(\n %s\n)\n%s" % ("\n ".join( # [str(base.tuple([name, value])) for name, value in flat.items()]), base.tuple(exprs)) key = "(\n %s\n)\n%s" % ( "\n ".join( [str(base.tuple([name, subenv[name.value]])) for name, expr in var_list]), base.tuple(exprs)) # print key if key in let_t._cache: # print "cache win for:\n%s" % (key,) # print "cached value %s for %s" % (let_t._cache[key], key) return base.Bounce(k, let_t._cache[key]) def with_value(v): let_t._cache[key] = v return base.Bounce(k, v) return base.Bounce(base.return_last, with_value, subenv, exprs)
def __str__(self): return '(lambda %s %s %s)' % ( self.name if self.name is not None else '<unnamed>', self.arg_labels, base.tuple(self.exprs))