Fix Nim version for Nim 1.0.4
[jackhill/mal.git] / nim / step7_quote.nim
index 7917849..0c534bc 100644 (file)
@@ -16,16 +16,16 @@ proc quasiquote(ast: MalType): MalType =
   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:
@@ -33,8 +33,9 @@ proc eval_ast(ast: MalType, env: var Env): MalType =
   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)
@@ -64,7 +65,7 @@ proc eval(ast: MalType, env: var Env): MalType =
         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):
@@ -83,7 +84,7 @@ proc eval(ast: MalType, env: var Env): MalType =
 
       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)
 
@@ -131,7 +132,7 @@ proc rep(str: string): string {.discardable.} =
 
 # 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) & "\")"