1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-17 17:20:29 +02:00

recommend #:replace

* doc/ref/api-modules.texi (Creating Guile Modules): Update text to
  recommend #:replace.
* module/srfi/srfi-19.scm (current-time): #:replace.
This commit is contained in:
Andy Wingo 2010-07-17 13:30:50 +02:00
parent 1c05a2a16d
commit d68a81e038
2 changed files with 16 additions and 23 deletions

View file

@ -383,29 +383,22 @@ with the same name that is not also ``replacing''. Normally a
replacement results in an ``override'' warning message, replacement results in an ``override'' warning message,
@code{#:replace} avoids that. @code{#:replace} avoids that.
This is useful for modules that export bindings that have the same In general, a module that exports a binding for which the @code{(guile)}
name as core bindings. @code{#:replace}, in a sense, lets Guile know module already has a definition should use @code{#:replace} instead of
that the module @emph{purposefully} replaces a core binding. It is @code{#:export}. @code{#:replace}, in a sense, lets Guile know that the
important to note, however, that this binding replacement is confined module @emph{purposefully} replaces a core binding. It is important to
to the name space of the module user. In other words, the value of the note, however, that this binding replacement is confined to the name
core binding in question remains unchanged for other modules. space of the module user. In other words, the value of the core binding
in question remains unchanged for other modules.
For instance, SRFI-39 exports a binding named Note that although it is often a good idea for the replaced binding to
@code{current-input-port} (@pxref{SRFI-39}) that is a function which remain compatible with a binding in @code{(guile)}, to avoid surprising
is upwardly compatible with the core @code{current-input-port} the user, sometimes the bindings will be incompatible. For example,
function. Therefore, SRFI-39 exports its version with SRFI-19 exports its own version of @code{current-time} (@pxref{SRFI-19
@code{#:replace}. Time}) which is not compatible with the core @code{current-time}
function (@pxref{Time}). Guile assumes that a user importing a module
SRFI-19, on the other hand, exports its own version of knows what she is doing, and uses @code{#:replace} for this binding
@code{current-time} (@pxref{SRFI-19 Time}) which is not compatible rather than @code{#:export}.
with the core @code{current-time} function (@pxref{Time}). Therefore,
SRFI-19 does not use @code{#:replace}.
The @code{#:replace} option can also be used by a module which is
intentionally producing a new special kind of environment and should
override any core or other bindings already in scope. For example
perhaps a logic processing environment where @code{<=} is an inference
instead of a comparison.
The @code{#:duplicates} (see below) provides fine-grain control about The @code{#:duplicates} (see below) provides fine-grain control about
duplicate binding handling on the module-user side. duplicate binding handling on the module-user side.

View file

@ -44,6 +44,7 @@
:use-module (srfi srfi-9) :use-module (srfi srfi-9)
:autoload (ice-9 rdelim) (read-line) :autoload (ice-9 rdelim) (read-line)
:use-module (ice-9 i18n) :use-module (ice-9 i18n)
:replace (current-time)
:export (;; Constants :export (;; Constants
time-duration time-duration
time-monotonic time-monotonic
@ -55,7 +56,6 @@
current-date current-date
current-julian-day current-julian-day
current-modified-julian-day current-modified-julian-day
current-time
time-resolution time-resolution
;; Time object and accessors ;; Time object and accessors
make-time make-time