1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00

Support for renaming bindings on module export.

* module/ice-9/boot-9.scm (module-export!, module-replace!)
  (module-re-export!): Allow members of export list to be pairs, mapping
  internal names to external ones.

* doc/ref/api-modules.texi (Creating Guile Modules): Update
  documentation for `#:export', `#:export-syntax', `#:replace',
  `#:re-export', `#:re-export-syntax', `export', and `re-export' to
  reflect new format for arguments.
This commit is contained in:
Julian Graham 2009-12-10 00:29:11 -05:00 committed by Andy Wingo
parent 820f33aaed
commit 78c22f5edc
2 changed files with 43 additions and 31 deletions

View file

@ -416,40 +416,42 @@ the module is used.
@item #:export @var{list} @item #:export @var{list}
@cindex export @cindex export
Export all identifiers in @var{list} which must be a list of symbols. Export all identifiers in @var{list} which must be a list of symbols
This is equivalent to @code{(export @var{list})} in the module body. or pairs of symbols. This is equivalent to @code{(export @var{list})}
in the module body.
@item #:re-export @var{list} @item #:re-export @var{list}
@cindex re-export @cindex re-export
Re-export all identifiers in @var{list} which must be a list of Re-export all identifiers in @var{list} which must be a list of
symbols. The symbols in @var{list} must be imported by the current symbols or pairs of symbols. The symbols in @var{list} must be
module from other modules. This is equivalent to @code{re-export} imported by the current module from other modules. This is equivalent
below. to @code{re-export} below.
@item #:export-syntax @var{list} @item #:export-syntax @var{list}
@cindex export-syntax @cindex export-syntax
Export all identifiers in @var{list} which must be a list of symbols. Export all identifiers in @var{list} which must be a list of symbols
The identifiers in @var{list} must refer to macros (@pxref{Macros}) or pairs of symbols. The identifiers in @var{list} must refer to
defined in the current module. This is equivalent to macros (@pxref{Macros}) defined in the current module. This is
@code{(export-syntax @var{list})} in the module body. equivalent to @code{(export-syntax @var{list})} in the module body.
@item #:re-export-syntax @var{list} @item #:re-export-syntax @var{list}
@cindex re-export-syntax @cindex re-export-syntax
Re-export all identifiers in @var{list} which must be a list of Re-export all identifiers in @var{list} which must be a list of
symbols. The symbols in @var{list} must refer to macros imported by symbols or pairs of symbols. The symbols in @var{list} must refer to
the current module from other modules. This is equivalent to macros imported by the current module from other modules. This is
@code{(re-export-syntax @var{list})} in the module body. equivalent to @code{(re-export-syntax @var{list})} in the module body.
@item #:replace @var{list} @item #:replace @var{list}
@cindex replace @cindex replace
@cindex replacing binding @cindex replacing binding
@cindex overriding binding @cindex overriding binding
@cindex duplicate binding @cindex duplicate binding
Export all identifiers in @var{list} (a list of symbols) and mark them Export all identifiers in @var{list} (a list of symbols or pairs of
as @dfn{replacing bindings}. In the module user's name space, this symbols) and mark them as @dfn{replacing bindings}. In the module
will have the effect of replacing any binding with the same name that user's name space, this will have the effect of replacing any binding
is not also ``replacing''. Normally a replacement results in an with the same name that is not also ``replacing''. Normally a
``override'' warning message, @code{#:replace} avoids that. replacement results in an ``override'' warning message,
@code{#:replace} avoids that.
This is useful for modules that export bindings that have the same This is useful for modules that export bindings that have the same
name as core bindings. @code{#:replace}, in a sense, lets Guile know name as core bindings. @code{#:replace}, in a sense, lets Guile know
@ -557,8 +559,11 @@ do not know anything about dangerous procedures.
@c end @c end
@deffn syntax export variable @dots{} @deffn syntax export variable @dots{}
Add all @var{variable}s (which must be symbols) to the list of exported Add all @var{variable}s (which must be symbols or pairs of symbols) to
bindings of the current module. the list of exported bindings of the current module. If @var{variable}
is a pair, its @code{car} gives the name of the variable as seen by the
current module and its @code{cdr} specifies a name for the binding in
the current module's public interface.
@end deffn @end deffn
@c begin (scm-doc-string "boot-9.scm" "define-public") @c begin (scm-doc-string "boot-9.scm" "define-public")
@ -568,9 +573,10 @@ Equivalent to @code{(begin (define foo ...) (export foo))}.
@c end @c end
@deffn syntax re-export variable @dots{} @deffn syntax re-export variable @dots{}
Add all @var{variable}s (which must be symbols) to the list of Add all @var{variable}s (which must be symbols or pairs of symbols) to
re-exported bindings of the current module. Re-exported bindings must the list of re-exported bindings of the current module. Pairs of
be imported by the current module from some other module. symbols are handled as in @code{export}. Re-exported bindings must be
imported by the current module from some other module.
@end deffn @end deffn
@node Module System Reflection @node Module System Reflection

View file

@ -2968,16 +2968,20 @@ module '(ice-9 q) '(make-q q-length))}."
(define (module-export! m names) (define (module-export! m names)
(let ((public-i (module-public-interface m))) (let ((public-i (module-public-interface m)))
(for-each (lambda (name) (for-each (lambda (name)
(let ((var (module-ensure-local-variable! m name))) (let* ((internal-name (if (pair? name) (car name) name))
(module-add! public-i name var))) (external-name (if (pair? name) (cdr name) name))
(var (module-ensure-local-variable! m internal-name)))
(module-add! public-i external-name var)))
names))) names)))
(define (module-replace! m names) (define (module-replace! m names)
(let ((public-i (module-public-interface m))) (let ((public-i (module-public-interface m)))
(for-each (lambda (name) (for-each (lambda (name)
(let ((var (module-ensure-local-variable! m name))) (let* ((internal-name (if (pair? name) (car name) name))
(external-name (if (pair? name) (cdr name) name))
(var (module-ensure-local-variable! m internal-name)))
(set-object-property! var 'replace #t) (set-object-property! var 'replace #t)
(module-add! public-i name var))) (module-add! public-i external-name var)))
names))) names)))
;; Re-export a imported variable ;; Re-export a imported variable
@ -2985,13 +2989,15 @@ module '(ice-9 q) '(make-q q-length))}."
(define (module-re-export! m names) (define (module-re-export! m names)
(let ((public-i (module-public-interface m))) (let ((public-i (module-public-interface m)))
(for-each (lambda (name) (for-each (lambda (name)
(let ((var (module-variable m name))) (let* ((internal-name (if (pair? name) (car name) name))
(external-name (if (pair? name) (cdr name) name))
(var (module-variable m internal-name)))
(cond ((not var) (cond ((not var)
(error "Undefined variable:" name)) (error "Undefined variable:" internal-name))
((eq? var (module-local-variable m name)) ((eq? var (module-local-variable m internal-name))
(error "re-exporting local variable:" name)) (error "re-exporting local variable:" internal-name))
(else (else
(module-add! public-i name var))))) (module-add! public-i external-name var)))))
names))) names)))
(defmacro export names (defmacro export names