1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-11 21:57:38 +03:00
mal/impls/groovy/step1_read_print.groovy

39 lines
577 B
Groovy
Raw Normal View History

import reader
import printer
import types.MalException
// READ
READ = { str ->
reader.read_str str
}
// EVAL
EVAL = { ast, env ->
ast
}
// PRINT
PRINT = { exp ->
printer.pr_str exp, true
}
// REPL
REP = { str ->
PRINT(EVAL(READ(str), [:]))
}
while (true) {
line = System.console().readLine 'user> '
if (line == null) {
break;
}
try {
println REP(line)
} catch(MalException ex) {
println "Error: ${printer.pr_str(ex.obj, true)}"
} catch(ex) {
println "Error: $ex"
ex.printStackTrace()
}
}