From 8cb5cda46cf3aef847ae3926dc53a5e5f87fe261 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Wed, 16 Apr 2014 23:57:50 -0500 Subject: All: move some fns to core. Major cleanup. - Don't import/require core until step4. - Define cond/or macros from step8 --- clojure/src/stepA_more.clj | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'clojure/src/stepA_more.clj') diff --git a/clojure/src/stepA_more.clj b/clojure/src/stepA_more.clj index 30eb8a6..d45d86a 100644 --- a/clojure/src/stepA_more.clj +++ b/clojure/src/stepA_more.clj @@ -149,21 +149,15 @@ [strng] (PRINT (EVAL (READ strng) repl-env))) -(defn _ref [k,v] (env/env-set repl-env k v)) - -;; Import types related functions -(doseq [[k v] core/core_ns] (_ref k v)) - -;; Defined using the language itself -(_ref 'readline readline/readline) -(_ref 'read-string reader/read-string) -(_ref 'eval (fn [ast] (EVAL ast repl-env))) -(_ref 'slurp slurp) +;; core.clj: defined using Clojure +(doseq [[k v] core/core_ns] (env/env-set repl-env k v)) +(env/env-set repl-env 'eval (fn [ast] (EVAL ast repl-env))) +;; core.mal: defined using the language itself (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! load-file (fn* [f] (eval (read-string (str \"(do \" (slurp f) \")\")))))") (defn -main [& args] (if args -- cgit v1.2.3