def scheme_eval(snippet): """Convert snippet into a single expression and scheme_eval it.""" # TODO: figure out how to do this more cleanly buf = scheme.buffer_lines(snippet.split('\n'), show_prompt=True) exprs = [] try: while True: exprs.append(scheme.scheme_read(buf)) except EOFError: pass env = scheme.create_global_frame() try: for expr in exprs[:-1]: scheme.scheme_eval(expr, env) return scheme.scheme_eval(exprs[-1], env) except scheme.SchemeError as err: return 'SchemeError' except BaseException as err: return type(err).__name__ + ' ' + str(err)