about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2024-03-23 15:51:44 -0500
committerCase Duckworth2024-03-23 15:51:44 -0500
commit7f5993dc2c4d074fb273673a7ad5fe6151dc7acb (patch)
treee755f39149d2f9cfd266b454684d7bbada339dec
parentBreak special forms out into their own table (diff)
downloadlam-7f5993dc2c4d074fb273673a7ad5fe6151dc7acb.tar.gz
lam-7f5993dc2c4d074fb273673a7ad5fe6151dc7acb.zip
Improve repl
-rw-r--r--repl.lua17
1 files changed, 14 insertions, 3 deletions
diff --git a/repl.lua b/repl.lua index 34e4c94..b198880 100644 --- a/repl.lua +++ b/repl.lua
@@ -4,6 +4,16 @@ local repl = {}
4local eval = require("eval").eval 4local eval = require("eval").eval
5local read = require("read").read 5local read = require("read").read
6 6
7local function schemeprint (x)
8 if x == true then
9 print("#t")
10 elseif x == false then
11 print("#f")
12 else
13 print(x)
14 end
15end
16
7function repl.repl (prompt) 17function repl.repl (prompt)
8 if not prompt then prompt = "lam> " end 18 if not prompt then prompt = "lam> " end
9 io.input():setvbuf("line") 19 io.input():setvbuf("line")
@@ -11,9 +21,10 @@ function repl.repl (prompt)
11 io.write(prompt) 21 io.write(prompt)
12 io.output():flush() 22 io.output():flush()
13 local input = io.read() 23 local input = io.read()
14 if input == nil then break end 24 if input ~= "" then
15 local value = eval(read(input)) 25 local value = eval(read(input))
16 if value then print(value) end 26 if value ~= nil then schemeprint(value) end
27 end
17 until false 28 until false
18end 29end
19 30