def write_to(self, port): port.write("#<record ") port.write(self.record_type.name.name) for f, value in self.fields.items(): port.write(" (") port.write(f) port.write(" ") write.write_to(value, port) port.write(")") port.write(">")
def repl(interpreter): interpreter.stdout.write(INTRO) interpreter.stdout.flush_output() reader = interpreter.reader(sys.stdin) while True: interpreter.stdout.write(PROMPT) interpreter.stdout.flush_output() try: expr = reader.read() except exceptions.ReaderError as e: interpreter.stdout.write("Error reading expression:\n") interpreter.stdout.write(str(e)) interpreter.stdout.newline() continue if base.eofp(expr): interpreter.stdout.newline() return try: result = eval.eval(expr, env=interpreter.global_env) except exceptions.EvalError as e: interpreter.stdout.write("Error evaluating expression:\n") interpreter.stdout.write(str(e)) interpreter.stdout.newline() continue except Exception as e: interpreter.stdout.write("Got exception:\n") interpreter.stdout.write(str(e)) interpreter.stdout.newline() continue interpreter.stdout.newline() write.write_to(result, interpreter.stdout) interpreter.stdout.newline()
def write_str(obj): stream = io.StringIO() port = ports.TextStreamPort.from_stream(stream) write.write_to(obj, port) return stream.getvalue()
def test_quote(self): stream = io.StringIO("' ( a b c )") result = self.reader(stream).read(stream) write.write_to(result, self.port) self.assertEqual(self.stream.getvalue(), "'(a b c)")
def test_empty_list(self): stream = io.StringIO("()") result = self.reader(stream).read(stream) write.write_to(result, self.port) self.assertEqual(self.stream.getvalue(), "()")