def build_lambda(word): def body(letters): if not letters: return 'x' elif letters[0] == 'A': return 'car(' + body(letters[1:]) + ')' else: return 'cdr(' + body(letters[1:]) + ')' return eval('lambda x: ' + body(word)) # Danger
def _eval(expr): """Evaluate an expression in the global environment""" from src.eval import eval return eval(expr, global_env)