4 READ
:= method(str
, MalReader
read_str(str
))
6 eval_ast
:= method(ast
, env
,
8 "MalSymbol", env
get(ast
),
9 "MalList", MalList
with(ast
map(a
, EVAL(a
, env
))),
10 "MalVector", MalVector
with(ast
map(a
, EVAL(a
, env
))),
14 keyObj
:= MalMap
keyToObj(k
)
15 m
atPut(MalMap
objToKey(EVAL(keyObj
, env
)), EVAL(v
, env
))
22 EVAL
:= method(ast
, env
,
23 if(ast
type != "MalList", return(eval_ast(ast
, env
)))
24 if(ast isEmpty
, return ast
)
25 if(ast
at(0) type == "MalSymbol",
28 return(env
set(ast
at(1), EVAL(ast
at(2), env
))),
30 letEnv
:= Env
with(env
)
32 ast
at(1) foreach(i
, e
,
35 letEnv
set(varName
, EVAL(e
, letEnv
))
38 return(EVAL(ast
at(2), letEnv
))
43 el
:= eval_ast(ast
, env
)
46 f
callWithArgList(args
)
49 PRINT
:= method(exp
, exp
malPrint(true
))
51 repl_env
:= Env
with(nil
)
52 repl_env
set(MalSymbol
with("+"), block(a
, b
, a
+ b
))
53 repl_env
set(MalSymbol
with("-"), block(a
, b
, a
- b
))
54 repl_env
set(MalSymbol
with("*"), block(a
, b
, a
* b
))
55 repl_env
set(MalSymbol
with("/"), block(a
, b
, a
/ b
))
57 RE
:= method(str
, EVAL(READ(str
), repl_env
))
59 REP
:= method(str
, PRINT(RE(str
)))
62 line
:= MalReadline
readLine("user> ")
64 if(line isEmpty
, continue)
65 e
:= try(REP(line
) println
)
67 ("Error: " .. (e error
)) println