next up previous contents
Next: Complex Data Type Up: Modules Previous: The USE Renames Facility

 

USE ONLY Statement

It is possible to restrict the availability of objects declared in a module made visible use association by using the ONLY clause of the USE statement. In this way name clashes can be avoided by only using those objects which are necessary. It has the following form:

 
USE < module-name > [ ONLY:< only-list >...]

The < only-list > can also contain renames (=>).

This method can be used as an alternative to renaming module entities, for example, a situation may arise where a user wishes to use 1 or 2 objects from a module but discovers that if the module is accessed by use association there are a couple of hundred name clashes. The simplest solution to this is to only allow the 1 or 2 objects to be seen by his / her program. These 1 or 2 objects can be renamed if desired.

For example,

    USE Stack, ONLY:Pos, IntegerPop => Pop
Only Pos and Pop are made accessible and the latter is renamed.

The USE statement, with its renaming and restrictive access facilities, gives great user control enabling two modules with similar names to be accessed by the same program with only minor inconvenience. In addition, the ONLY clause gives the compiler the option of just including the object code associated with the entities specified instead of the code for the whole module. This has the potential to make the executable code smaller and faster.

Now try this question gif

Return to corresponding overview page gif


next up previous contents
Next: Complex Data Type Up: Modules Previous: The USE Renames Facility

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.