# apply list
ast <- macroexpand(ast, env)
- if (!.list_q(ast)) return(ast)
+ if (!.list_q(ast)) return(eval_ast(ast, env))
switch(paste("l",length(ast),sep=""),
l0={ return(ast) },
Env.set(repl_env, "*ARGV*", new.list())
# core.mal: defined using the language itself
-. <- rep("(def! *host-language* \"R\")")
. <- rep("(def! not (fn* (a) (if a false true)))")
. <- rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))")
. <- rep("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))")
args <- commandArgs(trailingOnly = TRUE)
if (length(args) > 0) {
- Env.set(repl_env, "*ARGV*", new.listl(slice(list(args),2)))
- . <- rep(concat("(load-file \"", args[[1]], "\")"))
+ Env.set(repl_env, "*ARGV*", new.listl(slice(as.list(args),2)))
+ tryCatch({
+ . <- rep(concat("(load-file \"", args[[1]], "\")"))
+ }, error=function(err) {
+ cat("Error: ", get_error(err),"\n", sep="")
+ })
quit(save="no", status=0)
}
-. <- rep("(println (str \"Mal [\" *host-language* \"]\"))")
repeat {
line <- readline("user> ")
if (is.null(line)) { cat("\n"); break }