Node:Intro to Writing New Modules, Next:Intro to Modules and Extensions, Previous:Intro to Using Guile Modules, Up:Guile 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
form:
(export frob)
define-module
form with the keyword
export
:
(define-module (foo bar) #:export (frob))
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)
.
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)