commander-s/scheme/eval-environment.scm

46 lines
1.4 KiB
Scheme

(define *evaluation-environment*)
(define *evaluation-environment-name*)
(define *user-environment* #f)
(define (load-evaluation-environment package)
(let ((structure (reify-structure package)))
(load-structure structure)
(rt-structure->environment structure)))
(define (evaluation-environment-name)
(if (eq? *evaluation-environment*
*user-environment*)
(string->symbol "") ; aehm...
*evaluation-environment-name*))
(define (set-evaluation-package! package-name)
(set! *evaluation-environment*
(load-evaluation-environment package-name))
(set! *evaluation-environment-name* package-name))
(define (init-evaluation-environment! user-env)
(set-evaluation-package! user-env)
(set! *user-environment* (evaluation-environment)))
(define (evaluation-environment)
*evaluation-environment*)
(define (read-sexp-from-string string)
(let ((string-port (open-input-string string)))
(read string-port)))
(define (eval-string str . maybe-package-name)
(apply eval-s-expr (read-sexp-from-string str) maybe-package-name))
(define (eval-s-expr s-expr . maybe-package-name)
(let ((env (if (null? maybe-package-name)
(evaluation-environment)
(load-evaluation-environment (car maybe-package-name)))))
(eval s-expr env)))
(define (eval-s-expr/command s-expr)
(let ((command-env (load-evaluation-environment 'nuit-eval)))
(eval s-expr command-env)))