You can create shelves in your OmniMark program. Shelves may be of any supported data type, including record data types defined
using declare record
.
Shelves can be either global
or local
. The difference between these is that
global
shelves exist (and can be used) everywhere within a program, whereas local
shelves only exist
(and can be used) within the rule or function where they are declared.
Since shelves cannot be used until they are declared, global
shelf declarations usually appear at the
top of an OmniMark program, and local
shelves appear at the beginning of the rule or function in which they
are to be used. The scope of a shelf (global
or local
) must be indicated in the shelf declaration.
A shelf declaration that creates a global
integer
shelf named count1
looks like this:
global integer count1Once declared,
count1
can be used to store any positive or negative integer value.
To create a local
string
shelf named quotation
, you would use the shelf declaration:
local string quotationTo store a value in a
shelf
, you can use the set
keyword. For example:
set quotation to "Is this a dagger which I see before me?"
integer
shelf values can be assigned and changed the same way as string
shelves using
the set
action, but integer
shelves can also be manipulated using the increment
and decrement
actions. For example, to increase the value of the count1
shelf by
one, you need only say:
increment count1It is possible to increment or decrement the value of an
integer
shelf by the value of another integer
shelf. For example, you could decrement the value of count1
by the value of count2
with the following code:
decrement count1 by count2
The following is a program that makes use of a global
switch
shelf to decide which
output
action should be executed:
global switch question process set question to true process do when question ;checks if question is true output "to be" else output "not to be" doneNote that the output of this program will always be
to be
.
It is possible to declare a shelf with an initial value:
global integer count2 initial { 3 } global string quotation2 initial { "A horse!" } global switch status2 initial { true }
You can set a shelf to the value of another shelf. For example, the process
rule in the following
program will set the value of the global
integer
shelf var1
to the value of the
local
integer
shelf var2
and give you the output 8
:
global integer var1 process local integer var2 set var2 to 8 set var1 to var2 process output "%d(var1)"
A constant
is like a global
shelf, except that it must be given an initial value, and its
initial value cannot be changed. A constant
is declared by using the keyword constant
instead
of global
. A constant
is a good way to give a name to a value that the program will never
change.
constant integer days-in-week initial { 7 } constant integer months-in-year initial { 12 }