about summary refs log tree commit diff stats
path: root/repl.lua
blob: 3cdfe4e97ed44006114bf74ce7edd5b120deb8c6 (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
33
34
35
36
37
38
39
40
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