mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-09 21:40:33 +02:00
resolve-module #:ensure argument
* module/ice-9/boot-9.scm (resolve-module): Add #:ensure kwarg, defaulting to true. If true we make an empty module if none was found (the old behavior). Otherwise we return false. * test-suite/tests/modules.test ("resolve-module"): Add tests for old and new behavior.
This commit is contained in:
parent
5a8fc758b0
commit
7e3147666b
2 changed files with 23 additions and 5 deletions
|
@ -2420,7 +2420,7 @@ If there is no handler at all, Guile prints an error and then exits."
|
||||||
;; Define the-root-module as '(guile).
|
;; Define the-root-module as '(guile).
|
||||||
(module-define-submodule! root 'guile the-root-module)
|
(module-define-submodule! root 'guile the-root-module)
|
||||||
|
|
||||||
(lambda* (name #:optional (autoload #t) (version #f))
|
(lambda* (name #:optional (autoload #t) (version #f) #:key (ensure #t))
|
||||||
(let ((already (nested-ref-module root name)))
|
(let ((already (nested-ref-module root name)))
|
||||||
(cond
|
(cond
|
||||||
((and already
|
((and already
|
||||||
|
@ -2433,12 +2433,13 @@ If there is no handler at all, Guile prints an error and then exits."
|
||||||
(autoload
|
(autoload
|
||||||
;; Try to autoload the module, and recurse.
|
;; Try to autoload the module, and recurse.
|
||||||
(try-load-module name version)
|
(try-load-module name version)
|
||||||
(resolve-module name #f))
|
(resolve-module name #f #:ensure ensure))
|
||||||
(else
|
(else
|
||||||
;; No module found (or if one was, it had no public interface), and
|
;; No module found (or if one was, it had no public interface), and
|
||||||
;; we're not autoloading. Here's the weird semantics: we ensure
|
;; we're not autoloading. Make an empty module if #:ensure is true.
|
||||||
;; there's an empty module.
|
(or already
|
||||||
(or already (make-modules-in root name))))))))
|
(and ensure
|
||||||
|
(make-modules-in root name)))))))))
|
||||||
|
|
||||||
|
|
||||||
(define (try-load-module name version)
|
(define (try-load-module name version)
|
||||||
|
|
|
@ -136,6 +136,23 @@
|
||||||
(module-reverse-lookup (current-module) 'foo)))
|
(module-reverse-lookup (current-module) 'foo)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;;;
|
||||||
|
;;; Resolve-module.
|
||||||
|
;;;
|
||||||
|
|
||||||
|
(with-test-prefix "resolve-module"
|
||||||
|
|
||||||
|
(pass-if "#:ensure #t by default"
|
||||||
|
(module? (resolve-module (list (gensym)))))
|
||||||
|
|
||||||
|
(pass-if "#:ensure #t explicitly"
|
||||||
|
(module? (resolve-module (list (gensym)) #:ensure #t)))
|
||||||
|
|
||||||
|
(pass-if "#:ensure #f"
|
||||||
|
(not (resolve-module (list (gensym)) #:ensure #f))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
;;; Observers.
|
;;; Observers.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue