Commit | Line | Data |
---|---|---|
a9cd6543 JM |
1 | import reader |
2 | import printer | |
3 | import types.MalException | |
4 | ||
5 | // READ | |
6 | READ = { str -> | |
7 | reader.read_str str | |
8 | } | |
9 | ||
10 | // EVAL | |
11 | EVAL = { ast, env -> | |
12 | ast | |
13 | } | |
14 | ||
15 | ||
16 | PRINT = { exp -> | |
17 | printer.pr_str exp, true | |
18 | } | |
19 | ||
20 | // REPL | |
21 | REP = { str -> | |
22 | PRINT(EVAL(READ(str), [:])) | |
23 | } | |
24 | ||
25 | while (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 | } |