process/stepA: add gensym and clean `or` macro
authorDov Murik <dov.murik@gmail.com>
Thu, 21 Jan 2016 03:53:16 +0000 (22:53 -0500)
committerDov Murik <dov.murik@gmail.com>
Sat, 23 Jan 2016 04:47:52 +0000 (23:47 -0500)
process/stepA_mal.txt

index 1b67f95..2750cac 100644 (file)
@@ -53,7 +53,9 @@ rep("(def! *host-language* \"racket\")")
 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 cmdline_args: rep("(load-file \"" + args[0] + "\")"); exit 0