Merge pull request #238 from prt2121/pt/haskell-7.10.1
[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 if #arg > 0 and arg[1] == "--raw" then
29 readline.raw = true
30 end
31
32 while true do
33 line = readline.readline("user> ")
34 if not line then break end
35 xpcall(function()
36 print(rep(line))
37 end, function(exc)
38 if exc then
39 if types._malexception_Q(exc) then
40 exc = printer._pr_str(exc.val, true)
41 end
42 print("Error: " .. exc)
43 print(debug.traceback())
44 end
45 end)
46 end