Merge pull request #377 from asarhaddon/fix-runtests-pre-eval
[jackhill/mal.git] / d / step1_read_print.d
1 import std.stdio;
2 import std.string;
3 import readline;
4 import reader;
5 import printer;
6 import types;
7
8 MalType READ(string str)
9 {
10 return read_str(str);
11 }
12
13 MalType EVAL(MalType ast)
14 {
15 return ast;
16 }
17
18 string PRINT(MalType ast)
19 {
20 return pr_str(ast);
21 }
22
23 string rep(string str)
24 {
25 return PRINT(EVAL(READ(str)));
26 }
27
28 void main()
29 {
30 for (;;)
31 {
32 string line = _readline("user> ");
33 if (line is null) break;
34 if (line.length == 0) continue;
35 try
36 {
37 writeln(rep(line));
38 }
39 catch (Exception e)
40 {
41 writeln("Error: ", e.msg);
42 }
43 }
44 writeln("");
45 }