1 if(!exists("..readline..")) source("readline.r")
2 if(!exists("..types..")) source("types.r")
3 if(!exists("..reader..")) source("reader.r")
4 if(!exists("..printer..")) source("printer.r")
6 READ
<- function(str
) {
10 eval_ast
<- function(ast
, env
) {
12 env
[[as
.character(ast
)]]
13 } else if (.list_q(ast
)) {
14 new
.listl(lapply(ast
, function(a
) EVAL(a
, env
)))
15 } else if (.vector_q(ast
)) {
16 new
.vectorl(lapply(ast
, function(a
) EVAL(a
, env
)))
17 } else if (.hash_map_q(ast
)) {
20 lst
[[length(lst
)+1]] = k
21 lst
[[length(lst
)+1]] = EVAL(ast
[[k
]], env
)
29 EVAL
<- function(ast
, env
) {
30 #cat("EVAL: ", .pr_str(ast,TRUE), "\n", sep="")
32 return(eval_ast(ast
, env
))
36 if (length(ast
) == 0) {
39 el
<- eval_ast(ast
, env
)
41 return(do
.call(f
,el
[-1]))
44 PRINT
<- function(exp
) {
45 return(.pr_str(exp
, TRUE))
49 repl_env
[["+"]] <- function(a
,b
) a
+b
50 repl_env
[["-"]] <- function(a
,b
) a
-b
51 repl_env
[["*"]] <- function(a
,b
) a
*b
52 repl_env
[["/"]] <- function(a
,b
) a
/b
54 rep
<- function(str
) return(PRINT(EVAL(READ(str
), repl_env
)))
57 line
<- readline("user> ")
58 if (is
.null(line
)) { cat("\n"); break }
60 cat(rep(line
),"\n", sep
="")
61 }, error
=function(err
) {
62 cat("Error: ", get_error(err
),"\n", sep
="")
64 # R debug/fatal with tracebacks:
65 #cat(rep(line),"\n", sep="")