(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))
(define (is_macro_call ast env)
(and (list? ast)
+ (> (length ast) 0)
(and=> (env-check (car ast) env) is-macro?)))
(define (_macroexpand ast env)
(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))))