DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

(guile.info.gz) Using Guile Modules

Info Catalog (guile.info.gz) General Information about Modules (guile.info.gz) The Guile module system (guile.info.gz) Creating Guile Modules
 
 31.3.2 Using Guile Modules
 --------------------------
 
 To use a Guile module is to access either its public interface or a
 custom interface ( General Information about Modules).  Both
 types of access are handled by the syntactic form `use-modules', which
 accepts one or more interface specifications and, upon evaluation,
 arranges for those interfaces to be available to the current module.
 This process may include locating and loading code for a given module if
 that code has not yet been loaded, following %load-path ( Build
 Config).
 
    An "interface specification" has one of two forms.  The first
 variation is simply to name the module, in which case its public
 interface is the one accessed.  For example:
 
      (use-modules (ice-9 popen))
 
    Here, the interface specification is `(ice-9 popen)', and the result
 is that the current module now has access to `open-pipe', `close-pipe',
 `open-input-pipe', and so on ( Included Guile Modules).
 
    Note in the previous example that if the current module had already
 defined `open-pipe', that definition would be overwritten by the
 definition in `(ice-9 popen)'.  For this reason (and others), there is
 a second variation of interface specification that not only names a
 module to be accessed, but also selects bindings from it and renames
 them to suit the current module's needs.  For example:
 
      (use-modules ((ice-9 popen)
                    :select ((open-pipe . pipe-open) close-pipe)
                    :renamer (symbol-prefix-proc 'unixy:)))
 
    Here, the interface specification is more complex than before, and
 the result is that a custom interface with only two bindings is created
 and subsequently accessed by the current module.  The mapping of old to
 new names is as follows:
 
      (ice-9 popen) sees:             current module sees:
      open-pipe                       unixy:pipe-open
      close-pipe                      unixy:close-pipe
 
    This example also shows how to use the convenience procedure
 `symbol-prefix-proc'.
 
  -- Scheme Procedure: symbol-prefix-proc prefix-sym
      Return a procedure that prefixes its arg (a symbol) with
      PREFIX-SYM.
 
  -- syntax: use-modules spec ...
      Resolve each interface specification SPEC into an interface and
      arrange for these to be accessible by the current module.  The
      return value is unspecified.
 
      SPEC can be a list of symbols, in which case it names a module
      whose public interface is found and used.
 
      SPEC can also be of the form:
 
            (MODULE-NAME [:select SELECTION] [:renamer RENAMER])
 
      in which case a custom interface is newly created and used.
      MODULE-NAME is a list of symbols, as above; SELECTION is a list of
      selection-specs; and RENAMER is a procedure that takes a symbol
      and returns its new name.  A selection-spec is either a symbol or
      a pair of symbols `(ORIG . SEEN)', where ORIG is the name in the
      used module and SEEN is the name in the using module.  Note that
      SEEN is also passed through RENAMER.
 
      The `:select' and `:renamer' clauses are optional.  If both are
      omitted, the returned interface has no bindings.  If the `:select'
      clause is omitted, RENAMER operates on the used module's public
      interface.
 
      Signal error if module name is not resolvable.
 
  -- syntax: use-syntax module-name
      Load the module `module-name' and use its system transformer as
      the system transformer for the currently defined module, as well
      as installing it as the current system transformer.
 
Info Catalog (guile.info.gz) General Information about Modules (guile.info.gz) The Guile module system (guile.info.gz) Creating Guile Modules
automatically generated byinfo2html