Merge pull request #217 from dubek/lua-interop
[jackhill/mal.git] / julia / step1_read_print.jl
1 #!/usr/bin/env julia
2
3 push!(LOAD_PATH, pwd(), "/usr/share/julia/base")
4 import readline_mod
5 import reader
6 import printer
7
8 # READ
9 function READ(str)
10 reader.read_str(str)
11 end
12
13 # EVAL
14 function EVAL(ast, env)
15 ast
16 end
17
18 # PRINT
19 function PRINT(exp)
20 printer.pr_str(exp)
21 end
22
23 # REPL
24 function REP(str)
25 return PRINT(EVAL(READ(str), []))
26 end
27
28 while true
29 line = readline_mod.do_readline("user> ")
30 if line === nothing break end
31 try
32 println(REP(line))
33 catch e
34 if isa(e, ErrorException)
35 println("Error: $(e.msg)")
36 else
37 println("Error: $(string(e))")
38 end
39 bt = catch_backtrace()
40 Base.show_backtrace(STDERR, bt)
41 println()
42 end
43 end