#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)
elif u"macroexpand" == a0sym:
return macroexpand(ast[1], env)
elif u"try*" == a0sym:
+ if len(ast) < 3:
+ return EVAL(ast[1], env);
a1, a2 = ast[1], ast[2]
a20 = a2[0]
if isinstance(a20, MalSym):
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: