ObjectType:exists
From Lavish Software Wiki
Contents |
[edit]
Overview
This type exists for one reason and one reason only: To determine if the data sequence is still continuing. In a data sequence, the moment any object or member is not accessible, the sequence ends and becomes NULL. Casting to this type will demonstrate that the sequence is still continuing.
[edit]
Members
(none)
[edit]
Methods
(none)
[edit]
Returns
TRUE
[edit]
Examples
[edit]
Example 1
We will demonstrate a collection of int objects, representing the number of different fruits we have. Mind that it is perfectly acceptable to have 0 of a fruit.
DeclareVariable Fruits collection int
Fruits:Set[Apple,2]
Fruits:Set[Strawberry,10]
Fruits:Set[Banana,4]
Fruits:Set[Watermelon,0]
echo We have ${Fruits.Element[Apple]} apples
echo We have ${Fruits.Element[Blueberry]} blueberries
; Uh oh, we have NULL blueberries!
if "${Fruits.Element[Blueberry]}"
{
; This technically works to determine if we have blueberries, but that's
; because int is fair game in a calculation. If this were a collection
; of strings, we would absolutely need something else!
echo We have ${Fruits.Element[Blueberry]} blueberries
; This will not echo, because NULL is equal to 0, and this will only execute
; when the formula given to if is non-zero
}
else
{
; This "else" will execute both when there is no Blueberry entry in the
; collection, AND when there are 0 blueberries. So the following statement
; is actually not true when we know we have 0 blueberries!
echo We dont know how many blueberries we have!
}
; The correct way to do so is as follows:
if "!${Fruits.Element[Blueberry](exists)}"
{
; The following statement will always be correct. It will ONLY be displayed
; when there is no Blueberry entry!
echo We dont know how many blueberries we have!
}
if "!${Fruits.Element[Watermelon](exists)}"
{
; The following statement will also always be correct. Even though we have 0
; watermelons, the "exists" type gives TRUE, which is equal to 1. This means
; the only time this executes is when the data sequence is aborted before
; getting to the exists cast (when there is no entry!)
echo We dont know how many watermelons we have!
}
[edit]
Operates On
none
[edit]
