diff options
| author | Joel Martin <github@martintribe.org> | 2014-04-19 13:04:09 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-04-19 13:04:09 -0500 |
| commit | 86b689f3d7111a9fa13da389a30f3dfdf877d1a4 (patch) | |
| tree | d72b065f9f987e291f892ceee5a8640363bfd9df /clojure/src/step6_file.clj | |
| parent | 718887c3019c49fc807bc18fbd5feb975ec03c85 (diff) | |
| download | mal-86b689f3d7111a9fa13da389a30f3dfdf877d1a4.tar.gz mal-86b689f3d7111a9fa13da389a30f3dfdf877d1a4.zip | |
All: *ARGV* and *host-language*. Misc syncing/fixes.
Diffstat (limited to 'clojure/src/step6_file.clj')
| -rw-r--r-- | clojure/src/step6_file.clj | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/clojure/src/step6_file.clj b/clojure/src/step6_file.clj index 2aeb1be..5d080b9 100644 --- a/clojure/src/step6_file.clj +++ b/clojure/src/step6_file.clj @@ -86,20 +86,25 @@ ;; 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)))") (rep "(def! load-file (fn* [f] (eval (read-string (str \"(do \" (slurp f) \")\")))))") +;; 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))) |
