Next: Compatibility, Previous: Enums and Flags, Up: Reference Guide [Contents][Index]
The following procedures are in the (gi util)
library.
In core Guile, there are options to tailor handling of
same-named procedures imported into the same module
(see Creating Guile Modules in Guile Reference Manual).
The default-duplicate-binding-handler
procedure and the
#:duplicates
option to define-module
can be used to tailor
the strategy. Choosing a correct behaviour may become important
important when using GObject introspection when many methods,
procedures, and signals may have the same name.
In the (gi util)
library, the following additional helper
procedures are provided.
This utility procedure adds the symbol handler to the list of default duplicate handlers. handler will be placed at the start of the list, giving it highest priority.
In the case of duplicate bindings whose values are equal (as in eq?
), they are accepted without raising a warning.
Another strategy to mitigate the problems posed by same-named
methods, procedures, and variables is to use the #:renamer
option
of use-modules
or use-typelibs
. Core Guile provides the
symbol-prefix-proc
renamer procedure, which can be used to apply
a prefix to the name of all imported procedures and variables.
This module provides the protect*
renamer. It is more targeted
than symbol-prefix-proc
; it applies a prefix and/or suffix to
those imports whose names are in a list of provided symbols.
Returns a renamer, which “protects” symbol, a symbol or
symbols, a list of symbols from being overridden, by prepending
prefix and appending suffix, both symbols. If neither prefix nor suffix
are given, '%
is used as prefix.
Constants, which can be applied to protect*
.
%rnrs-syntax
contains R6RS syntax keywords from the
(rnrs syntax)
module. Most of these are also very important to R5RS.
%r5rs-procedures
contains the names of common R5RS procedures that
Guile always provides.
These can be used alone or together to protect important names in Scheme
code. The following example, for instance, prepends gtk::
to imported
GObject procedures which match R6RS syntax or R5RS procedures.
(use-modules (gi) (gi util)) (use-typelibs (("Gtk" "3.0") #:renamer (protect* (append %rnrs-syntax %safe-r5rs) 'gtk::)))
While importing procedures or methods with the same names a Scheme syntax may cause confusion, importing procedures or methods with the same name as Guile procedures is usually not a problem due to method overloading via GOOPS.
Note: While this can prevent you from accidentally messing up important procedures, it is usually a better strategy to only include what you need.
In the (gi util)
library, the following helper procedures are provided
for use with SRFI-4-type uniform numeric vectors.
Next: Compatibility, Previous: Enums and Flags, Up: Reference Guide [Contents][Index]