swirl
Guide to OmniMark 9   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
Prerequisite Concepts     Related Topics  

Module parameterization

Imported modules can be parameterized. You can supply a module you're importing with functions, globals, constants, catches and opaque types. Modules declare what they need to be supplied.

Module parameterization is the inverse of exporting. Exporting ships things from within modules to the outside -- from the modules to their importers. Module parameterization ships things from outside of modules into them -- from the importers into the modules being imported. Exporting is what you mostly want to do, but parameterization is occasionally what you have to do. The most common example is supplying a "call back" function to a module, such as supplying a comparison function to a sorting module.

There are two parts to supplying module parameterization. Within the module you have to declare what you require from whoever's importing you. You do this by providing declarations of the things to be supplied, but with the keyword require in place of define or declare or prefixing global or constant. For functions, you leave out the as or elsewhere part. For globals and constants you only specify the type and name. And for opaques you leave out the creator. For example:

  require opaque sortable-type
  require switch function compare (value sortable-type a, value sortable-type b)
  require global integer total-count
  require constant integer maximum-count
  require catch maximum-count-exceeded by value string who

The other half of parameterizing modules is supplying the required things from whoever is importing the module. Supplying consists merely of following the keyword supply with name of the thing to be supplied -- the thing has to be declared prior to the supply, so nothing more need be said about it. On the other hand, you may have to tell the import which of its requirements this supply is satisfying -- which you do following as. For example:

  import "sort.xmd" prefixed by person-
     supply person-record as sortable-type
     supply compare-person as compare

The as and the following name can be left out when the two names are the same, as in:

  import "countfiles.xmd" unprefixed
     supply total-count
     supply maximum-count
     supply maximum-count-exceeded

supply and use parts of an import can be mixed together and put in any order.

Names must be declared before they are supplied. They can either be fully defined, or they can be predeclared in an elsewhere declaration:

  define record person-record elsewhere
  define switch function compare-person value person-record a
    with value person-record b
    elsewhere
  
  import "sort.xmd" prefixed by person-
     supply person-record as sortable-type
     supply compare-person as compare

elsewhere declarations can be used for names imported from other modules as well as names being defined by the current module or program.

Prerequisite Concepts
 
  Related Topics
 
 

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ LEGACY LIBRARIES ] [ ERRORS ]

OmniMark 9.1.0 Documentation Generated: September 2, 2010 at 1:35:14 pm
If you have any comments about this section of the documentation, please use this form.

Copyright © Stilo International plc, 1988-2010.