forth: Self-hosted mal passes all tests
[jackhill/mal.git] / lua / step1_read_print.lua
1 #!/usr/bin/env lua
2
3 local readline = require('readline')
4 local utils = require('utils')
5 local reader = require('reader')
6 local printer = require('printer')
7
8 -- read
9 function READ(str)
10 return reader.read_str(str)
11 end
12
13 -- eval
14 function EVAL(ast, env)
15 return ast
16 end
17
18 -- print
19 function PRINT(exp)
20 return printer._pr_str(exp, true)
21 end
22
23 -- repl
24 function rep(str)
25 return PRINT(EVAL(READ(str),""))
26 end
27
28 while true do
29 line = readline.readline("user> ")
30 if not line then break end
31 xpcall(function()
32 print(rep(line))
33 end, function(exc)
34 if exc then
35 if types._malexception_Q(exc) then
36 exc = printer._pr_str(exc.val, true)
37 end
38 print("Error: " .. exc)
39 print(debug.traceback())
40 end
41 end)
42 end