about summary refs log tree commit diff stats
path: root/repl.lua
blob: b1988806e1e4c35851bc158b4b034f8dacc545ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
--- lam.repl

local repl = {}
local eval = require("eval").eval
local read = require("read").read

local function schemeprint (x)
	if x == true then
		print("#t")
	elseif x == false then
		print("#f")
	else
		print(x)
	end
end

function repl.repl (prompt)
	if not prompt then prompt = "lam> " end
	io.input():setvbuf("line")
	repeat
		io.write(prompt)
		io.output():flush()
		local input = io.read()
		if input ~= "" then
			local value = eval(read(input))
			if value ~= nil then schemeprint(value) end
		end
	until false
end

---
return repl