www.delorie.com/gnu/docs/guile/guile_17.html   search  
Buy GNU books!

Guile Reference Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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:

After exporting, other modules can access the exported items simply by using use-modules to load the module (foo bar).

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003