mirror of
https://github.com/kanaka/mal.git
synced 2024-11-11 00:52:44 +03:00
a9cd654347
I'm away from my main workstation for a week and unfortunately, I only copied the code but not the branch with full history so this is just the implementation. However, the history isn't all that interesting (mostly just the steps one at a time) and I wanted to get this out there.
39 lines
559 B
Groovy
39 lines
559 B
Groovy
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: ${ex.message}"
|
|
} catch(ex) {
|
|
println "Error: $ex"
|
|
ex.printStackTrace()
|
|
}
|
|
}
|