else:
return list(symbol "cons", quasiquote(ast.list[0]), quasiquote(list(ast.list[1 .. ^1])))
-proc eval(ast: MalType, env: var Env): MalType
+proc eval(ast: MalType, env: Env): MalType
proc eval_ast(ast: MalType, env: var Env): MalType =
case ast.kind
of Symbol:
result = env.get(ast.str)
of List:
- result = list ast.list.mapIt(MalType, it.eval(env))
+ result = list ast.list.mapIt(it.eval(env))
of Vector:
- result = vector ast.list.mapIt(MalType, it.eval(env))
+ result = vector ast.list.mapIt(it.eval(env))
of HashMap:
result = hash_map()
for k, v in ast.hash_map.pairs:
else:
result = ast
-proc eval(ast: MalType, env: var Env): MalType =
+proc eval(ast: MalType, env: Env): MalType =
var ast = ast
+ var env = env
template defaultApply =
let el = ast.eval_ast(env)
let
a1 = ast.list[1]
a2 = ast.list[2]
- var let_env = env
+ var let_env = initEnv(env)
case a1.kind
of List, Vector:
for i in countup(0, a1.list.high, 2):
of "do":
let last = ast.list.high
- discard (list ast.list[1 .. <last]).eval_ast(env)
+ discard (list ast.list[1 ..< last]).eval_ast(env)
ast = ast.list[last]
# Continue loop (TCO)
# core.mal: defined using mal itself
rep "(def! not (fn* (a) (if a false true)))"
-rep "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"
+rep "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \"\nnil)\")))))"
if paramCount() >= 1:
rep "(load-file \"" & paramStr(1) & "\")"