(guile.info.gz) Intro to Writing New Modules
Info Catalog
(guile.info.gz) Intro to Using Guile Modules
(guile.info.gz) Guile Modules
(guile.info.gz) Intro to Modules and Extensions
5.5.2 Intro to Writing New Modules
----------------------------------
Of course it is possible to write modules yourself. Using modules for
structuring your programs makes them more readable and lets you
distribute them more easily. Also, explicitly defining the procedures
and variables which are exported from a module adds documentation to the
source and specifies the interface a module provides.
In Guile, you can create new modules and switch to existing modules
in order to add bindings to them using the syntactic form
`define-module'.
(define-module (foo bar))
(define (frob x) x)
Will create the module `(foo bar)'.(1) All definitions following
this statement will add bindings to the module `(foo bar)', and these
bindings will not be visible outside of the module. To make the
bindings accessible to other modules, you have to export them
explicitly using one of the following means:
* Export them with the `export' form:
(export frob)
* Include them into the `define-module' form with the keyword
`export':
(define-module (foo bar)
#:export (frob))
* Change the definition of `frob' to use `define-public', which is a
combination of `define' and `export'.
(define-public (frob x) x)
After exporting, other modules can access the exported items simply
by using `use-modules' to load the module `(foo bar)'.
---------- Footnotes ----------
(1) It is only convention that the module names in this section have
two elements. One or more than two elements are perfectly fine, such
as `(foo)' or `(foo bar braz)'
Info Catalog
(guile.info.gz) Intro to Using Guile Modules
(guile.info.gz) Guile Modules
(guile.info.gz) Intro to Modules and Extensions
automatically generated byinfo2html