Add gensym and clean `or` macro to stepA of 19 implementations (part 3)
[jackhill/mal.git] / vb / stepA_mal.vb
index 6778e0a..013b609 100644 (file)
@@ -278,7 +278,9 @@ Namespace Mal
             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)))))))))")
 
             If args.Length > fileIdx Then
                 REP("(load-file """ & args(fileIdx) & """)")