; xscheme.ini - initialization code for XScheme version 0.28

(load "macros.s")
(load "qquote.s")

; this version of EVAL knows about the optional enviroment parameter
(define (eval x #!optional env)
  ((if (default-object? env)
     (compile x)
     (compile x env))))

(define old-apply apply)
(define (apply f . args)
  (old-apply f (old-apply list* args)))

(define (autoload-from-file file syms #!optional env)
  (map (lambda (sym) (put sym '%autoload file)) syms)
  '())
  
(define (*unbound-handler* sym cont)
  (let ((file (get sym '%autoload)))
    (if file (load file))
    (if (not (bound? sym))
      (error "unbound variable" sym))
    (cont '())))

(define head car)
(define (tail x) (force (cdr x)))
(define empty-stream? null?)
(define the-empty-stream '())

(macro cons-stream
  (lambda (x)
    (list 'cons (cadr x) (list 'delay (caddr x)))))

(macro make-environment
  (lambda (x)
    (append '(let ()) (cdr x) '((the-environment)))))

(define initial-user-environment (the-environment))

(macro case
  (lambda (form)
    (let ((test (cadr form))
          (sym (gensym)))
      `(let ((,sym ,test))
         (cond ,@(map (lambda (x)
                        (cond ((eq? (car x) 'else)
                               x)
			      ((atom? (car x))
			       `((eqv? ,sym ',(car x)) ,@(cdr x)))
			      (else
                               `((memv ,sym ',(car x)) ,@(cdr x)))))
                      (cddr form)))))))

; load the files mentioned on the command line
(define (loader n)
  (let ((arg (getarg n)))
    (if arg
      (begin
        (display ";Loading ")
        (write arg)
        (newline)
        (load arg)
        (loader (1+ n))))))
(loader 1)

(define (*initialize*)
  (loader 1)
  (*toplevel*))
