remainder shelf-type argument-name (argument-separator)?


A remainder argument is a special kind of argument. It is used to pass a number of discrete values to a function as a single argument. OmniMark does this by "creating" a read-only shelf argument initialized by the values being passed.

If a function has a remainder argument, it must be the last argument. In the case that remainder is the first and only argument of a function, and it has no leading herald, the second herald must be defined.

Within the function, the remainder argument behaves exactly as a read-only shelf. The size of the shelf depends on the number of values passed.

Remainder arguments cannot be optional. If no values are passed in the remainder argument, then the created argument shelf is still specified. It simply has no items.

An item on a remainder argument shelf may be passed to a function either individually as a value argument or as part of a remainder shelf argument. The entire remainder argument shelf can be passed as a read-only argument.

External functions can have remainder arguments.

The following sample shows that by using the argument separator before the remainder argument, the separator can act as both the introductory herald for the argument as well as the item separator if the second herald is omitted.

To illustrate this point, the second herald for the remainder has been omitted, and therefore the first herald acts in the dual role described above.

  define integer function sum
                 (value integer x0 , remainder integer xx) as
     local integer s
     set s to x0
     repeat over xx
        increment s by xx
     return s

A call to "sum" would look like this:

  set k to sum (1, 2, 3, 4, 5)   ; "k" gets the value 15.

In this function, the remainder argument is the first (and only) argument. As there is no leading herald, in this case the second herald must be defined.

Related Syntax