www.delorie.com/gnu/docs/kawa/kawa_72.html   search  
 
Buy GNU books!


Kawa, the Java-based Scheme system

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

10.8.4 Requiring (importing) a module

You can import a module into the current namespace with require.

Syntax: require modulespec
The modulespec can be either a <classname> or a 'featurename. In either case the names exported by the specified module (class) are added to the current set of visible names.

If modulespec is <classname> where classname is an instance module (it has a public default constructor), and if no module instance for that class has been registered in the current environment, then a new instance is created and registered (using a "magic" identifier). If the module class either inherits from gnu.expr.ModuleBody or implements java.lang.Runnable then the corresponding run method is executed. (This is done after the instance is registered so that cycles can be handled.) These actions (creating, registering, and running the module instance) are done both at compile time and at run time, if necessary.

All the public fields of the module class are then incorporated in the current set of local visible names in the current module. This is done at compile time - no new bindings are created at run-time (except for the magic binding used to register the module instance), and the imported bindings are private to the current module. References to the imported bindings will be compiled as field references, using the module instance (except for static fields).

If the modulespec is 'featurename then the featurename is looked up (at compile time) in the "feature table" which yields the implementing <classname>.

For some examples, you may want to look in the gnu/kawa/slib directory.


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