DISABLE FDs (REMOVE ME).
[jackhill/mal.git] / es6 / step1_read_print.mjs
1 import rl from './node_readline.js'
2 const readline = rl.readline
3 import { BlankException, read_str } from './reader'
4 import { pr_str } from './printer'
5
6 // read
7 const READ = str => read_str(str)
8
9 // eval
10 const EVAL = (ast, env) => ast
11
12 // print
13 const PRINT = exp => pr_str(exp, true)
14
15 // repl
16 const REP = str => PRINT(EVAL(READ(str), {}))
17
18 while (true) {
19 let line = readline('user> ')
20 if (line == null) break
21 try {
22 if (line) { console.log(REP(line)) }
23 } catch (exc) {
24 if (exc instanceof BlankException) { continue }
25 if (exc instanceof Error) { console.warn(exc.stack) }
26 else { console.warn(`Error: ${exc}`) }
27 }
28 }