plsql: add dockerfile. Lots of cleanup/renaming.
[jackhill/mal.git] / guile / step8_macros.scm
index 169fb06..af36411 100644 (file)
 
 (define *toplevel*
   (receive (b e) (unzip2 core.ns)
-    (make-Env #:binds b #:exprs (map (lambda (x) (make-func x)) e))))
+    (make-Env #:binds b #:exprs (map make-func e))))
 
 (define (READ)
-  (read_str (readline "user> ")))
+  (read_str (_readline "user> ")))
 
 (define (eval_ast ast env)
   (define (_eval x) (EVAL x env))
@@ -54,6 +54,7 @@
 
 (define (is_macro_call ast env)
   (and (list? ast)
+       (> (length ast) 0)
        (and=> (env-check (car ast) env) is-macro?)))
 
 (define (_macroexpand ast env)
@@ -91,6 +92,7 @@
     (let ((ast (_macroexpand ast env)))
       (match ast
         ((? non-list?) (eval_ast ast env))
+        (() ast)
         (('defmacro! k v)
          (let ((c (EVAL v env)))
            (callable-is_macro-set! c #t)
 
 (define (PRINT exp)
   (and (not (eof-object? exp))
-       ;;(add-history str)
        (format #t "~a~%" (pr_str exp #t))))
 
 (define (LOOP continue?)
 (EVAL-string "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))")
 (EVAL-string "(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)))))))")
 (EVAL-string "(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)
+
+(let ((args (cdr (command-line))))
+  (cond
+   ((> (length args) 0)
+    ((*toplevel* 'set) '*ARGV* (cdr args))
+    (EVAL-string (string-append "(load-file \"" (car args) "\")")))
+   (else (REPL))))