def test_scheme_list(self): x = interop.scheme_list([1, 2]) self.assertTrue(base.pairp(x)) self.assertEqual(x.car, 1) self.assertTrue(base.pairp(x.cdr)) self.assertEqual(x.cdr.car, 2) self.assertTrue(base.nullp(x.cdr.cdr))
def display_pair_to(pair, port): if (base.symbolp(pair.car) and pair.car.name == "quote" and base.pairp(pair.cdr) and base.nullp(pair.cdr.cdr)): port.write("'") display_to(pair.cdr.car, port) else: port.write("(") display_to(pair.car, port) cur = pair.cdr while base.pairp(cur): port.write(" ") display_to(cur.car, port) cur = cur.cdr port.write(")")
def test_pair(self): pair = base.cons(1, base.null()) self.assertTrue(base.pairp(pair)) self.assertEqual(pair.car, 1) self.assertTrue(base.nullp(pair.cdr)) pair.car = "hello" self.assertEqual(pair.car, "hello")
def compile_expr(self, expr): if (base.numberp(expr) or base.stringp(expr) or base.booleanp(expr)): return self.compile_const(expr) elif base.symbolp(expr): return self.compile_variable(expr) elif base.pairp(expr): return self.compile_call(expr) else: msg = "Bad expr for compilation: {}".format(expr) raise CompileError(msg)
def compile_define(self, lvalue, *rest): if base.symbolp(lvalue): if len(rest) < 1: raise CompileError( "define: missing value for identifier") if len(rest) > 1: raise CompileError( "define: multiple values for identifier") return self.compile_define_var(lvalue, rest[0]) elif base.pairp(lvalue): return self.compile_define_proc(lvalue.car, lvalue.cdr, *rest) else: raise CompileError("define: invalid syntax")
def from_scheme_list(list_): result = [] while base.pairp(list_): result.append(list_.car) list_ = list_.cdr return result
def test_pairp(self): self.assertFalse(base.pairp(base.null())) self.assertFalse(base.pairp(5)) self.assertTrue(base.pairp(base.cons(None, base.null())))