3 push!(LOAD_PATH, pwd(), "/usr/share/julia/base")
17 function eval_ast(ast, env)
18 if typeof(ast) == Symbol
20 elseif isa(ast, Array) || isa(ast, Tuple)
21 map((x) -> EVAL(x,env), ast)
23 [EVAL(x[1],env) => EVAL(x[2], env) for x=ast]
29 function EVAL(ast, env)
31 #println("EVAL: $(printer.pr_str(ast,true))")
32 if !isa(ast, Array) return eval_ast(ast, env) end
33 if isempty(ast) return ast end
37 return env_set(env, ast[2], EVAL(ast[3], env))
38 elseif symbol("let*") == ast[1]
40 for i = 1:2:length(ast[2])
41 env_set(let_env, ast[2][i], EVAL(ast[2][i+1], let_env))
47 eval_ast(ast[2:end-1], env)
51 cond = EVAL(ast[2], env)
52 if cond === nothing || cond === false
63 elseif symbol("fn*") == ast[1]
65 (args...) -> EVAL(ast[3], Env(env, ast[2], Any[args...])),
68 el = eval_ast(ast, env)
69 f, args = el[1], el[2:end]
72 env = Env(f.env, f.params, args)
89 return PRINT(EVAL(READ(str), repl_env))
92 # core.jl: defined using Julia
93 repl_env = Env(nothing, core.ns)
94 env_set(repl_env, :eval, (ast) -> EVAL(ast, repl_env))
95 env_set(repl_env, symbol("*ARGV*"), ARGS[2:end])
97 # core.mal: defined using the language itself
98 REP("(def! not (fn* (a) (if a false true)))")
99 REP("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))")
102 REP("(load-file \"$(ARGS[1])\")")
107 line = readline_mod.do_readline("user> ")
108 if line === nothing break end
112 if isa(e, ErrorException)
113 println("Error: $(e.msg)")
115 println("Error: $(string(e))")
117 # TODO: show at least part of stack
118 if !isa(e, StackOverflowError)
119 bt = catch_backtrace()
120 Base.show_backtrace(STDERR, bt)