make, swift3: fix parsing empty literal sequences.
[jackhill/mal.git] / rpython / stepA_mal.py
index 0e3d54e..5fd5592 100644 (file)
@@ -86,6 +86,7 @@ def EVAL(ast, env):
         #print("EVAL %s" % printer._pr_str(ast))
         if not types._list_Q(ast):
             return eval_ast(ast, env)
+        if len(ast) == 0: return ast
 
         # apply list
         ast = macroexpand(ast, env)
@@ -195,8 +196,8 @@ def entry_point(argv):
     REP("(def! not (fn* (a) (if a false true)))", repl_env)
     REP("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env)
     REP("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))", repl_env)
-    REP("(def! *gensym-counter* (atom 0))", repl_env)
-    REP("(def! gensym (fn* [] (symbol (str \"G__\" (swap! *gensym-counter* (fn* [x] (+ 1 x)))))))", repl_env)
+    REP("(def! inc (fn* [x] (+ x 1)))", repl_env)
+    REP("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))", repl_env)
     REP("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))", repl_env)
 
     if len(argv) >= 2: