From 5cc96a0fb06fa7d86563f4cb64e5fa9d4f6a09f9 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Mon, 13 Nov 2017 01:00:33 -0500 Subject: Big-ass coding binge presents: a Lisp. This implements a continuation-passing interpreter, which means we get tail calls ferfree. I stopped short of implementing call/cc, because I don't think we need it, but we can get there if we have to. --- primer.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 primer.py (limited to 'primer.py') diff --git a/primer.py b/primer.py new file mode 100644 index 0000000..2c6d73a --- /dev/null +++ b/primer.py @@ -0,0 +1,37 @@ +import actinide +import actinide.types as t +import actinide.builtin as b +import actinide.evaluator as e + +session = actinide.Session() +program = session.read(""" +(begin + 1 + 1.0 + "Hello" + (define a + (lambda (b) (values 1 2.2 "three" a b))) + (define pp + (lambda () (pp))) + (print (a "foo")) + (print (eval (list (symbol "a") "bar"))) + (print 0 (values 1 2 3) 4 5) + (pp)) +""") + +def begin(*args): + if args: + return args[-1] + return None + +def values(*args): + return args + +session.bind_builtin(values) +session.bind_void(print) +session.bind_fn(begin) +session.bind_fn(t.list) +session.bind_fn(session.symbol) +session.bind_builtin(session.eval) + +session.eval(program) -- cgit v1.2.3