--- lam.repl local m = {} local read = require("read") local eval = require("eval") local pp = require("pp").pp local function schemeprint (x) -- if x == nil then return end if x == true then print("#t") elseif x == false then print("#f") else print(x) end end function m.repl (prompt, infile, out) -- PROMPT should be a string, INFILE is a filename, and OUT is either a -- filename, nil (in which case it will be stdout), or false (which -- suppresses output) local inport = read.inport(infile) if out ~= false then io.output(out) end io.output():setvbuf("line") if prompt then stderr = io.open("/dev/stderr", "w") -- Linux-only ! end while true do if prompt then stderr:write(prompt) stderr:flush() end local x = read.read(inport) if x then local val = eval.eval(x) if out ~= false then schemeprint(val) end end end inport:close() stderr:close() io.output():close() end -------- return m