3 push!(LOAD_PATH, pwd(), "/usr/share/julia/base")
16 function eval_ast(ast, env)
17 if typeof(ast) == Symbol
19 elseif isa(ast, Array) || isa(ast, Tuple)
20 map((x) -> EVAL(x,env), ast)
22 [EVAL(x[1],env) => EVAL(x[2], env) for x=ast]
28 function EVAL(ast, env)
29 if !isa(ast, Array) return eval_ast(ast, env) end
30 if isempty(ast) return ast end
34 env_set(env, ast[2], EVAL(ast[3], env))
35 elseif symbol("let*") == ast[1]
37 for i = 1:2:length(ast[2])
38 env_set(let_env, ast[2][i], EVAL(ast[2][i+1], let_env))
42 eval_ast(ast[2:end], env)[end]
44 cond = EVAL(ast[2], env)
45 if cond === nothing || cond === false
54 elseif symbol("fn*") == ast[1]
55 (args...) -> EVAL(ast[3], Env(env, ast[2], Any[args...]))
57 el = eval_ast(ast, env)
58 f, args = el[1], el[2:end]
71 return PRINT(EVAL(READ(str), repl_env))
74 # core.jl: defined using Julia
75 repl_env = Env(nothing, core.ns)
77 # core.mal: defined using the language itself
78 REP("(def! not (fn* (a) (if a false true)))")
81 line = readline_mod.do_readline("user> ")
82 if line === nothing break end
86 if isa(e, ErrorException)
87 println("Error: $(e.msg)")
89 println("Error: $(string(e))")
91 if !isa(e, StackOverflowError)
92 bt = catch_backtrace()
93 Base.show_backtrace(STDERR, bt)