diff options
| author | Joel Martin <github@martintribe.org> | 2014-03-24 16:32:24 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-03-24 16:32:24 -0500 |
| commit | 3169070063b2cb877200117ebb384269d73bcb93 (patch) | |
| tree | 23de3db1ea5c37afd21a45b6ed7771f56a08c0c4 /js/step0_repl.js | |
| download | mal-3169070063b2cb877200117ebb384269d73bcb93.tar.gz mal-3169070063b2cb877200117ebb384269d73bcb93.zip | |
Current state of mal for Clojure West lighting talk.
Diffstat (limited to 'js/step0_repl.js')
| -rw-r--r-- | js/step0_repl.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/js/step0_repl.js b/js/step0_repl.js new file mode 100644 index 0000000..5fa10f2 --- /dev/null +++ b/js/step0_repl.js @@ -0,0 +1,42 @@ +if (typeof module !== 'undefined') { + var readline = require('./node_readline'); +} + +// read +function READ(str) { + return str; +} + +// eval +function EVAL(ast, env) { + return eval(ast); +} + +// print +function PRINT(exp) { + return exp; +} + +// repl +var rep = function(str) { return PRINT(EVAL(READ(str), {})); }; + +if (typeof require === 'undefined') { + // Asynchronous browser mode + readline.rlwrap(function(line) { return rep(line); }, + function(exc) { + if (exc.stack) { console.log(exc.stack); } else { console.log(exc); } + }); +} else if (require.main === module) { + // Synchronous node.js commandline mode + while (true) { + var line = readline.readline("user> "); + if (line === null) { break; } + try { + if (line) { console.log(rep(line)); } + } catch (exc) { + if (exc.stack) { console.log(exc.stack); } else { console.log(exc); } + } + } +} else { + exports.rep = rep; +} |
