diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2017-11-13 01:00:33 -0500 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2017-11-13 01:01:34 -0500 |
| commit | 5cc96a0fb06fa7d86563f4cb64e5fa9d4f6a09f9 (patch) | |
| tree | 40052668ffe030452b45e3a2d6be8d8fc24acdee /primer.py | |
| parent | 6a635660bd7b47238642d4a552782687352555ac (diff) | |
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.
Diffstat (limited to 'primer.py')
| -rw-r--r-- | primer.py | 37 |
1 files changed, 37 insertions, 0 deletions
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) |
