properly implement tco and add step7:quote
[jackhill/mal.git] / groovy / step1_read_print.groovy
CommitLineData
a9cd6543
JM
1import reader
2import printer
3import types.MalException
4
5// READ
6READ = { str ->
7 reader.read_str str
8}
9
10// EVAL
11EVAL = { ast, env ->
12 ast
13}
14
15// PRINT
16PRINT = { exp ->
17 printer.pr_str exp, true
18}
19
20// REPL
21REP = { str ->
22 PRINT(EVAL(READ(str), [:]))
23}
24
25while (true) {
26 line = System.console().readLine 'user> '
27 if (line == null) {
28 break;
29 }
30 try {
31 println REP(line)
32 } catch(MalException ex) {
dd7a4f55 33 println "Error: ${printer.pr_str(ex.obj, true)}"
a9cd6543
JM
34 } catch(ex) {
35 println "Error: $ex"
36 ex.printStackTrace()
37 }
38}