aboutsummaryrefslogtreecommitdiff
path: root/clojure/src/step9_interop.clj
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-19 13:04:09 -0500
committerJoel Martin <github@martintribe.org>2014-04-19 13:04:09 -0500
commit86b689f3d7111a9fa13da389a30f3dfdf877d1a4 (patch)
treed72b065f9f987e291f892ceee5a8640363bfd9df /clojure/src/step9_interop.clj
parent718887c3019c49fc807bc18fbd5feb975ec03c85 (diff)
downloadmal-86b689f3d7111a9fa13da389a30f3dfdf877d1a4.tar.gz
mal-86b689f3d7111a9fa13da389a30f3dfdf877d1a4.zip
All: *ARGV* and *host-language*. Misc syncing/fixes.
Diffstat (limited to 'clojure/src/step9_interop.clj')
-rw-r--r--clojure/src/step9_interop.clj23
1 files changed, 14 insertions, 9 deletions
diff --git a/clojure/src/step9_interop.clj b/clojure/src/step9_interop.clj
index 40f2b5c..677599c 100644
--- a/clojure/src/step9_interop.clj
+++ b/clojure/src/step9_interop.clj
@@ -138,6 +138,7 @@
;; 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)))
+(env/env-set repl-env '*ARGV* ())
;; core.mal: defined using the language itself
(rep "(def! not (fn* [a] (if a false true)))")
@@ -145,15 +146,19 @@
(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))))))))")
+;; repl loop
+(defn repl-loop []
+ (let [line (readline/readline "user> ")]
+ (when line
+ (when-not (re-seq #"^\s*$|^\s*;.*$" line) ; blank/comment
+ (try
+ (println (rep line))
+ (catch Throwable e
+ (clojure.repl/pst e))))
+ (recur))))
+
(defn -main [& args]
+ (env/env-set repl-env '*ARGV* (rest args))
(if args
(rep (str "(load-file \"" (first args) "\")"))
- (loop []
- (let [line (readline/readline "user> ")]
- (when line
- (when-not (re-seq #"^\s*$|^\s*;.*$" line) ; blank/comment
- (try
- (println (rep line))
- (catch Throwable e
- (clojure.repl/pst e))))
- (recur))))))
+ (repl-loop)))