def interpret_file(filename, env): """Interpret a list source file, returning the value of the last expression""" with open(filename, 'r') as f: source = f.read() results = [eval(ast, env) for ast in parse_multiple(source)] return results[-1]
def interpret_file(filename, env=None): """ Interpret a lisp file Accepts the name of a lisp file containing a series of statements. Returns the value of the last expression of the file. """ if env is None: env = Environment() with open(filename, 'r') as sourcefile: source = "".join(sourcefile.readlines()) asts = parse_multiple(source) results = [evaluate(ast, env) for ast in asts] return unparse(results[-1])
def interpret_file(filename, env=None): """ Interpret a lisp file Accepts the name of a lisp file containing a series of statements. Returns the value of the last expression of the file. """ if env is None: env = Environment() with open(filename, 'r') as sourcefile: source = "".join(sourcefile.readlines()) asts = parse_multiple(source) imports = filter(lambda a: a[0] == 'import', asts) asts = filter(lambda a: a[0] != 'import', asts) results = [evaluate(ast, env) for ast in asts] for imp in imports: interpret_file(imp[1][1:-1], env) # If the Slow Loris file contains only comments or includes, don't fail. if len(results) == 0: return '' return unparse(results[-1])