Water 5-Common Data Types-NumberIncrement the value of the named field
Contract| Return type | wob | | Parameter key | Default value | Type | | a_key | req | | step | 1 | integer | | if_missing | "error" | type.<one_of "error" "create"/> | | Water Contract<method increment
a_key =req
step =1
if_missing="error"=<type.one_of "error" "create"/>/> | |
See also: copy_down_data, plus
Adds the value of step to the value of the field identified by
_subject.a_key . _subject defaults to the local environment.
<set x=6>
<increment "x" />
</set>
 | 7 |
Notice that a_key is passed as a string .
To be able to use increment on an inherited field, the field
should be copied down from the parent class using copy_down_data .
Attempting to call increment on an inherited field without copying
it down will result in a "field not found" error.
Example: Data not copied down
<class foo bar=20 />
<set a=<foo /> />
<try if_error="field not found">
a.<increment "bar" />
</try>
 | "field not found" |
Example: Data copied down
<class foo bar=20 >
<method make>
.<copy_down_data />
_subject
</method>
</class>
<set a=<foo /> />
<try if_error="field not found">
a.<increment "bar" />
</try> | 21 |
a wob
| Parameter key | Default value | Type |
| step | 1 | integer |
This field sets the "step value", the amount to add to the
current value.
Example: Add 2 by incrementing
<set x=6>
<increment "x" step=2 />
</set>
 | 8 |
a wob
| Parameter key | Default value | Type |
| if_missing | "error" | type.<one_of "error" "create"/> |
Whenever a field lookup is performed in Water there is a chance that the
field will not be found. If the field is "missing", Water can take
various actions to try to fix the situation. increment provides
two possible values for if_missing.
a wobif_missing="error"
If
a_key is not found, throw an error.
<try if_error="error">
<set x=6>
<increment "y" />
</set>
</try>
 | "error" |
a wobif_missing="create"
If
a_key is not found, create the key, set it to zero,
and add the
step value..
<try if_error="error">
<set x=6>
<increment "y" step=2 if_missing="create" />
</set>
</try>
 | 2 |
© Copyright 2007 Clear Methods, Inc.