diff options
-rw-r--r-- | base.lua | 8 | ||||
-rw-r--r-- | eval.lua | 15 |
2 files changed, 8 insertions, 15 deletions
diff --git a/base.lua b/base.lua index 9c5b5b7..6dc71e4 100644 --- a/base.lua +++ b/base.lua | |||
@@ -5,14 +5,6 @@ local type = require "type" | |||
5 | local isNull = type.isNull | 5 | local isNull = type.isNull |
6 | 6 | ||
7 | base.env = { | 7 | base.env = { |
8 | begin = | ||
9 | function (r) | ||
10 | local r = r | ||
11 | while not isNull(r.cdr) do | ||
12 | r = r.cdr | ||
13 | end | ||
14 | return r.car | ||
15 | end, | ||
16 | ["+"] = | 8 | ["+"] = |
17 | function (r) | 9 | function (r) |
18 | local r, a = r, 0 | 10 | local r, a = r, 0 |
diff --git a/eval.lua b/eval.lua index e926bc4..565ead5 100644 --- a/eval.lua +++ b/eval.lua | |||
@@ -32,9 +32,13 @@ function eval.Proc (params, body, env) | |||
32 | p, a = p.cdr, a.cdr | 32 | p, a = p.cdr, a.cdr |
33 | end | 33 | end |
34 | pp.pp(self.body) | 34 | pp.pp(self.body) |
35 | return eval.eval( | 35 | local b = self.body |
36 | self.body, | 36 | local e = eval.Env(inner, self.env) |
37 | eval.Env(inner, self.env)) | 37 | while not isNull(b.cdr) do |
38 | eval.eval(b.car, e) | ||
39 | b = b.cdr | ||
40 | end | ||
41 | return eval.eval(b.car, e) | ||
38 | end, | 42 | end, |
39 | } | 43 | } |
40 | return setmetatable(v, mt) | 44 | return setmetatable(v, mt) |
@@ -54,10 +58,7 @@ function eval.eval (x, env) | |||
54 | env[args.car] = eval.eval(args.cdr.car, env) | 58 | env[args.car] = eval.eval(args.cdr.car, env) |
55 | return nil | 59 | return nil |
56 | elseif op == "lambda" or op == "lam" then | 60 | elseif op == "lambda" or op == "lam" then |
57 | return eval.Proc( | 61 | return eval.Proc(args.car, args.cdr, env) |
58 | args.car, | ||
59 | Cons("begin", args.cdr), -- i don't like this | ||
60 | env) | ||
61 | elseif op == "if" then | 62 | elseif op == "if" then |
62 | assert(not isNull(args.cdr), "Malformed 'if'") | 63 | assert(not isNull(args.cdr), "Malformed 'if'") |
63 | local test, conseq, alt = | 64 | local test, conseq, alt = |