new.listl(lapply(ast, function(a) EVAL(a, env)))
} else if (.vector_q(ast)) {
new.vectorl(lapply(ast, function(a) EVAL(a, env)))
+ } else if (.hash_map_q(ast)) {
+ lst <- list()
+ for(k in ls(ast)) {
+ lst[[length(lst)+1]] = k
+ lst[[length(lst)+1]] = EVAL(ast[[k]], env)
+ }
+ new.hash_mapl(lst)
} else {
ast
}
repeat {
#cat("EVAL: ", .pr_str(ast,TRUE), "\n", sep="")
- if (!.list_q(ast)) {
- return(eval_ast(ast, env))
- }
+ if (!.list_q(ast)) { return(eval_ast(ast, env)) }
+ if (length(ast) == 0) { return(ast) }
# 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) },
# core.r: defined using R
for(k in names(core_ns)) { Env.set(repl_env, k, core_ns[[k]]) }
Env.set(repl_env, "eval", function(ast) EVAL(ast, repl_env))
-Env.set(repl_env, "*ARGV*", function(ast) EVAL(ast, repl_env))
+Env.set(repl_env, "*ARGV*", new.list())
# core.mal: defined using the language itself
. <- rep("(def! not (fn* (a) (if a false true)))")
. <- rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))")
+args <- commandArgs(trailingOnly = TRUE)
+if (length(args) > 0) {
+ Env.set(repl_env, "*ARGV*", new.listl(slice(as.list(args),2)))
+ . <- rep(concat("(load-file \"", args[[1]], "\")"))
+ quit(save="no", status=0)
+}
repeat {
line <- readline("user> ")