(closure-ccenv? object)))
(register-predicate! environment? 'environment)
+(define (->environment object #!optional caller)
+ (let ((caller (if (default-object? caller) '->environment caller)))
+ (cond ((environment? object) object)
+ ((library->environment-helper object) => library-environment)
+ ((name->package object) => package/environment)
+ ((procedure? object) (procedure-environment object))
+ (else (error:wrong-type-argument object "environment" caller)))))
+
(define (environment-has-parent? environment)
(cond ((system-global-environment? environment)
#f)
(define library-name (library-accessor 'name))
(define library-parsed-contents (library-accessor 'parsed-contents))
(define library-parsed-imports (library-accessor 'parsed-imports))
-(define library-syntaxed-contents (library-accessor 'syntaxed-contents))
\ No newline at end of file
+(define library-syntaxed-contents (library-accessor 'syntaxed-contents))
+
+(define (library->environment-helper name)
+ (if (library? name)
+ (and (name 'has? 'environment)
+ name)
+ (and (library-name? name)
+ (registered-library? name host-library-db)
+ (let ((library (registered-library name host-library-db)))
+ (and (library 'has? 'environment)
+ library)))))
\ No newline at end of file
(define (package-name? object)
(list-of-type? object symbol?))
+(define (package-name=? name1 name2)
+ (or (and (null? name1) (null? name2))
+ (and (pair? name1)
+ (pair? name2)
+ (eq? (car name1) (car name2))
+ (package-name=? (cdr name1) (cdr name2)))))
+
(define (package/reference package name)
(lexical-reference (package/environment package) name))
(define (find-package name #!optional error?)
(let package-loop ((packages *packages*))
- (if (null? packages)
- (if error?
- (error "Unable to find package:" name)
- #f)
- (if (let name-loop ((name1 name)
- (name2 (package/name (car packages))))
- (cond ((and (null? name1) (null? name2)) #t)
- ((or (null? name1) (null? name2)) #f)
- ((eq? (car name1) (car name2))
- (name-loop (cdr name1) (cdr name2)))
- (else #f)))
+ (if (pair? packages)
+ (if (package-name=? name (package/name (car packages)))
(car packages)
- (package-loop (cdr packages))))))
+ (package-loop (cdr packages)))
+ (begin
+ (if error? (error "Unable to find package:" name))
+ #f))))
(define (name-append name package)
(let loop ((names (package/name package)))
(interaction-i/o-port #f)
(working-directory-pathname
(working-directory-pathname))
+ (current-library-db (current-library-db))
(param:nearest-cmdl cmdl)
(param:standard-error-hook #f)
(param:standard-warning-hook #f)
(set-repl/environment! (nearest-repl) environment)
environment))
-(define (->environment object #!optional caller)
- (let ((caller (if (default-object? caller) '->environment caller)))
- (cond ((environment? object) object)
- ((package? object) (package/environment object))
- ((procedure? object) (procedure-environment object))
- (else
- (let ((package
- (let ((package-name
- (cond ((symbol? object) (list object))
- ((list? object) object)
- (else #f))))
- (and package-name
- (name->package package-name)))))
- (if (not package)
- (error:wrong-type-argument object "environment" caller))
- (package/environment package))))))
-
(define (re #!optional index)
(repl-eval (repl-history/read (repl/reader-history (nearest-repl))
(if (default-object? index) 1 index))))
(files "environment")
(parent (runtime))
(export ()
+ ->environment
compiled-procedure/environment
environment-arguments
environment-assign!
(parent (runtime))
(export ()
(interaction-environment nearest-repl/environment) ;R7RS
- ->environment
abort->nearest
abort->previous
abort->top-level
(parent (runtime library))
(export (runtime)
copy-library-db
+ library-bound-names
+ library-contents
+ library-db?
+ library-environment
+ library-imports-used
+ library-imports
+ library-name
library-export-from
library-export-to
library-export=?
library-import-from-library
library-import-to
library-import=?
- library-import?)
+ library-import?
+ library?
+ registered-libraries
+ registered-library
+ registered-library?)
+ (export (runtime environment)
+ library->environment-helper)
(export (runtime library)
define-automatic-property
library-contents
- library-db?
- library-environment
library-eval-result
library-exporter
library-export->list
library-exports
library-filename
library-imports-from
- library-imports-used
library-import->list
- library-imports
library-imports-environment
- library-name
library-parsed-contents
library-parsed-imports
library-syntaxed-contents
- library?
list->library-export
list->library-import
make-library
make-library-export
make-library-import
register-libraries!
- register-library!
- registered-libraries
- registered-library
- registered-library?))
+ register-library!))
(define-package (runtime library parser)
(files "library-parser")