Add gensym and clean `or` macro to stepA of 19 implementations (part 3)
[jackhill/mal.git] / awk / stepA_mal.awk
index 2b5a948..06cebce 100644 (file)
@@ -566,7 +566,9 @@ function main(str, ret, i, idx)
        rep("(def! not (fn* (a) (if a false true)))")
        rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))")
        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)))))))")
-       rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))")
+       rep("(def! *gensym-counter* (atom 0))")
+       rep("(def! gensym (fn* [] (symbol (str \"G__\" (swap! *gensym-counter* (fn* [x] (+ 1 x)))))))")
+       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)))))))))")
 
        idx = types_allocate()
        env_set(repl_env, "'*ARGV*", "(" idx)