contentsconceptssyntaxlibrariessampleserrorsindex
Full text search
Functions: shelves and arguments
Prerequisite Concepts     Related Syntax  

Passing a shelf reference as a function argument sets up an interaction between the function and the passed shelf in its caller.

When a shelf is passed as a function argument, the selected item becomes the current item of the function argument. If the shelf being passed in has an indexer, then the item selected by the indexer becomes the current item of the shelf argument. If the shelf being passed in has no indexer, then the currently selected item of that shelf is used as the current item of the function argument.

Care must be taken in writing functions that have read-only or modifiable arguments. It must not be assumed that the "lastmost" item of a passed shelf is its current item.

A shelf passed as a read-only argument cannot be modified when accessed by its argument name. If the argument that was passed refers to a global shelf, however, the function can access the shelf by its global name, and modify it that way. Since the read-only argument still refers to the same shelf, it appears as if the read-only argument has been modified.

The same kind of trick can be done by passing the same shelf as both a read-only argument and a modifiable argument. Since they refer to the same shelf, modifying the modifiable argument shelf effectively modifies the read-only shelf.

Needless to say, passing a shelf to a function where there is a possibility that the passed global shelf may be modified by the function is deprecated in general, whether or not a read-only or modifiable argument is involved. Doing so tends to produce unexpected behavior.

A similar problem does not exist with value and remainder arguments, because the value is captured as part of the call, and no later modification of any global value within the function is going to modify the passed value.

Prerequisite Concepts
     Functions
   Functions: argument classes
   Functions: passing a shelf as a modifiable argument
   Functions: passing a shelf as a read-only argument
 
  Related Syntax
   define function
 
----

Top [CONTENTS] [CONCEPTS] [SYNTAX] [LIBRARIES] [SAMPLES] [ERRORS] [INDEX]

Generated: April 21, 1999 at 2:00:48 pm
If you have any comments about this section of the documentation, send email to [email protected]

Copyright © OmniMark Technologies Corporation, 1988-1999.