Merge pull request #14 from anton-trunov/guide-small-fix
[jackhill/mal.git] / js / step0_repl.js
1 if (typeof module !== 'undefined') {
2 var readline = require('./node_readline');
3 }
4
5 // read
6 function READ(str) {
7 return str;
8 }
9
10 // eval
11 function EVAL(ast, env) {
12 return eval(ast);
13 }
14
15 // print
16 function PRINT(exp) {
17 return exp;
18 }
19
20 // repl
21 var rep = function(str) { return PRINT(EVAL(READ(str), {})); };
22
23 // repl loop
24 if (typeof require !== 'undefined' && require.main === module) {
25 // Synchronous node.js commandline mode
26 while (true) {
27 var line = readline.readline("user> ");
28 if (line === null) { break; }
29 try {
30 if (line) { printer.println(rep(line)); }
31 } catch (exc) {
32
33 if (exc.stack) { printer.println(exc.stack); }
34 else { printer.println(exc); }
35 }
36 }
37 }