def test_self_evaluation(self): self.assertEqual(visp.evaluate(visp.Exact(5), visp.Env()), visp.Exact(5)) self.assertEqual(visp.evaluate(visp.Inexact(6.0), visp.Env()), visp.Inexact(6.0)) self.assertEqual(visp.evaluate(visp.true, visp.Env()), visp.true) self.assertEqual(visp.evaluate(visp.false, visp.Env()), visp.false)
def test_exact(self): self.assertEqual(visp.evaluate(visp.read("1"), visp.Env()), 1)
def test_quote(self): self.assertEqual( visp.evaluate(visp.read("'(1 2 3)"), visp.Env()).car, 1)
def test_symbol(self): self.assertEqual(visp.evaluate(visp.read("a"), visp.Env({'a': 2})), 2)
def test_inexact(self): self.assertEqual(visp.evaluate(visp.read("#i10"), visp.Env()), 10.0)
def test_sub_mixed(self): self.assertEqual( visp.evaluate(visp.read("(- #i100 #e20 #e40 #e1)"), visp.Env()), 39.0)
def test_inexact_add(self): self.assertEqual( visp.evaluate(visp.read("""(+ #i100 #i100)"""), visp.Env()), 200.0)
class VispShell(cmd.Cmd): intro = 'Welcome to the Visp shell. Type help or ? to list commands.\n' prompt = '> ' env = None def preloop(self): visp.load_prelude(self.env) def do_repr(self, line): self.default(line, to_string=repr) def do_env(self, line): print(self.env.to_string()) def default(self, line, to_string=str): try: print(to_string(visp.evaluate(visp.read(line), self.env))) except Exception as exc: print(traceback.format_exc()) def do_EOF(self, line): print() return True if __name__ == '__main__': vs = VispShell() vs.env = visp.Env() vs.cmdloop()
def setUp(self): self.base_env = visp.Env({'a': visp.Exact(2)})
def setUp(self): self.base_env = visp.Env() self.base_env.set( 'print', visp.evaluate(visp.read("(lambda x x)"), self.base_env)) visp.load_prelude(self.base_env)