about summary refs log tree commit diff stats
path: root/repl.lua
diff options
context:
space:
mode:
Diffstat (limited to 'repl.lua')
-rw-r--r--repl.lua41
1 files changed, 41 insertions, 0 deletions
diff --git a/repl.lua b/repl.lua new file mode 100644 index 0000000..3cdfe4e --- /dev/null +++ b/repl.lua
@@ -0,0 +1,41 @@
1--- lam.repl
2
3local repl = {}
4local eval = require "eval"
5local read = require "read"
6local util = require "util"
7
8function schemestr(x)
9 if type(x) == "table" then
10 local ts = "(" .. schemestr(util.pop(x))
11 for i,v in ipairs(x) do
12 ts = string.format("%s %s", ts, schemestr(v))
13 end
14 ts = ts .. ")"
15 return ts
16 elseif x == true then
17 return "#t"
18 elseif x == false then
19 return "#f"
20 else
21 return tostring(x)
22 end
23end
24
25function repl.repl (prompt)
26 prompt = prompt or "lam> "
27 repeat
28 io.write(prompt)
29 io.output():flush()
30 input = io.read()
31 if input == ",q" or input == ",quit" then
32 break
33 else
34 val = eval(read(input))
35 if val then print(schemestr(val)) end
36 end
37 until false
38end
39
40---
41return repl