All: *ARGV* and *host-language*. Misc syncing/fixes.
[jackhill/mal.git] / mal / stepA_more.mal
index 1af0d25..3e2a258 100644 (file)
 ;; core.mal: defined directly using mal
 (map (fn* [data] (env-set repl-env (nth data 0) (nth data 1))) core_ns)
 (env-set repl-env 'eval (fn* [ast] (EVAL ast repl-env)))
+(env-set repl-env '*ARGV* (rest *ARGV*))
 
 ;; core.mal: defined using the new language itself 
 (rep (str "(def! *host-language* \"" *host-language* "-mal\")"))
 (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))))))))")
 
-(def! -main (fn* [] 
+;; repl loop
+(def! repl-loop (fn* []
   (let* [line (readline "mal-user> ")]
     (if line
       (do
         (if (not (= "" line))
           (try*
-            (let* [res (rep line)]
-              (println res))
+            (println (rep line))
             (catch* exc
               (println "Uncaught exception:" exc))))
-        (-main))))))
-(-main)
+        (repl-loop))))))
+
+(def! -main (fn* [& args] 
+  (if (> (count args) 0)
+    (rep (str "(load-file \"" (first args) "\")"))
+    (do
+      (rep "(println (str \"Mal [\" *host-language* \"]\"))")
+      (repl-loop)))))
+(apply -main *ARGV*)