rep('(def! not (fn* (a) (if a false true)))');
rep("(def! load-file "
- "(fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))");
+ "(fn* (f) (eval (read-string (str \"(do \" (slurp f) \"\nnil)\")))))");
}
MalType READ(String x) => reader.read_str(x);
String PRINT(MalType x) => printer.pr_str(x);
String rep(String x) {
- var parsed;
- try {
- parsed = READ(x);
- } on reader.ParseException catch (e) {
- return e.message;
- }
-
- var evaledAst;
- try {
- evaledAst = EVAL(parsed, replEnv);
- } on NotFoundException catch (e) {
- return "'${e.value}' not found";
- }
- return PRINT(evaledAst);
+ return PRINT(EVAL(READ(x), replEnv));
}
const prompt = 'user> ';
var output;
try {
output = rep(input);
+ } on reader.ParseException catch (e) {
+ stdout.writeln("Error: '${e.message}'");
+ continue;
+ } on NotFoundException catch (e) {
+ stdout.writeln("Error: '${e.value}' not found");
+ continue;
+ } on MalException catch (e) {
+ stdout.writeln("Error: ${printer.pr_str(e.value)}");
+ continue;
} on reader.NoInputException {
continue;
}