about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2024-04-15 22:00:37 -0500
committerCase Duckworth2024-04-15 22:00:37 -0500
commit6c49847668e01d45cf56ec2b2e4fbf312957ee3d (patch)
treea4f85b67e41c7c03d0fa6830c187020d74157f65
parentRefactor type.character (diff)
downloadlam-6c49847668e01d45cf56ec2b2e4fbf312957ee3d.tar.gz
lam-6c49847668e01d45cf56ec2b2e4fbf312957ee3d.zip
Change names and hoist eval
read is unimplemented and load is buggy
-rw-r--r--core.lua7
-rw-r--r--eval.lua6
-rw-r--r--load.lua24
3 files changed, 30 insertions, 7 deletions
diff --git a/core.lua b/core.lua index 3e4773a..4f84f7f 100644 --- a/core.lua +++ b/core.lua
@@ -16,7 +16,12 @@ local function fold (kons, knil, r)
16 end 16 end
17end 17end
18 18
19local env = {} 19local env = type.environment({}, {})
20
21env["interaction-environment"] = function (r)
22 assert_arity(r,0,0)
23 return env
24end
20 25
21---[[ EQUIVALENCE ]]--- 26---[[ EQUIVALENCE ]]---
22 27
diff --git a/eval.lua b/eval.lua index 4b8f782..342624f 100644 --- a/eval.lua +++ b/eval.lua
@@ -6,7 +6,7 @@ local assert_arity = type.assert_arity
6local util = require("util") 6local util = require("util")
7local error = util.error 7local error = util.error
8 8
9m.special_forms = { 9m.primitives = {
10 quote = 10 quote =
11 function (r, _) 11 function (r, _)
12 assert_arity(r,1,1) 12 assert_arity(r,1,1)
@@ -89,8 +89,8 @@ function m.eval (x, env)
89 return x 89 return x
90 else 90 else
91 local op, args = x[1], x[2] 91 local op, args = x[1], x[2]
92 if m.special_forms[op] then 92 if m.primitives[op] then
93 return m.special_forms[op](args, env) 93 return m.primitives[op](args, env)
94 else -- procedure application 94 else -- procedure application
95 local fn = m.eval(op, env) 95 local fn = m.eval(op, env)
96 local params = {} 96 local params = {}
diff --git a/load.lua b/load.lua index 7f14207..db2651f 100644 --- a/load.lua +++ b/load.lua
@@ -15,9 +15,21 @@ local function schemeprint (x)
15 end 15 end
16end 16end
17 17
18local function handle_error (e) 18function core.environment.read (r)
19 local start = e:find(": ") 19 type.assert_arity(r,1,1)
20 return e:sub(start + 2) 20 error("unimplemented")
21end
22
23function core.environment.eval (r)
24 type.assert_arity(r,1,2)
25 local form = r[1]
26 local env = r[2][1] or core.environment
27 return eval.eval(form, env)
28end
29
30function core.environment.load (r)
31 type.assert_arity(r,1,1)
32 return m.load(tostring(r[1]))
21end 33end
22 34
23function m.load (filename, interactive) 35function m.load (filename, interactive)
@@ -29,6 +41,12 @@ function m.load (filename, interactive)
29 else 41 else
30 io.output():setvbuf("no") 42 io.output():setvbuf("no")
31 end 43 end
44
45 local function handle_error (e)
46 local start = e:find(": ")
47 return e:sub(start + 2)
48 end
49
32 repeat 50 repeat
33 if interactive then 51 if interactive then
34 io.stderr:write(interactive.prompt or "") 52 io.stderr:write(interactive.prompt or "")