Merge pull request #238 from prt2121/pt/haskell-7.10.1
[jackhill/mal.git] / lua / step1_read_print.lua
CommitLineData
9d42904e
JM
1#!/usr/bin/env lua
2
3local readline = require('readline')
4local utils = require('utils')
5local reader = require('reader')
6local printer = require('printer')
7
8-- read
9function READ(str)
10 return reader.read_str(str)
11end
12
13-- eval
14function EVAL(ast, env)
15 return ast
16end
17
18-- print
19function PRINT(exp)
20 return printer._pr_str(exp, true)
21end
22
23-- repl
24function rep(str)
25 return PRINT(EVAL(READ(str),""))
26end
27
3e0b36dc
JM
28if #arg > 0 and arg[1] == "--raw" then
29 readline.raw = true
30end
31
9d42904e
JM
32while 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)
46end