From 70ec5254814f9531e5ca2024465d0e01130306b7 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 21 Feb 2024 09:28:49 -0600 Subject: Initial commit --- repl.lua | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 repl.lua (limited to 'repl.lua') diff --git a/repl.lua b/repl.lua new file mode 100644 index 0000000..3cdfe4e --- /dev/null +++ b/repl.lua @@ -0,0 +1,41 @@ +--- lam.repl + +local repl = {} +local eval = require "eval" +local read = require "read" +local util = require "util" + +function schemestr(x) + if type(x) == "table" then + local ts = "(" .. schemestr(util.pop(x)) + for i,v in ipairs(x) do + ts = string.format("%s %s", ts, schemestr(v)) + end + ts = ts .. ")" + return ts + elseif x == true then + return "#t" + elseif x == false then + return "#f" + else + return tostring(x) + end +end + +function repl.repl (prompt) + prompt = prompt or "lam> " + repeat + io.write(prompt) + io.output():flush() + input = io.read() + if input == ",q" or input == ",quit" then + break + else + val = eval(read(input)) + if val then print(schemestr(val)) end + end + until false +end + +--- +return repl -- cgit 1.4.1-21-gabe81