Chapter 3 The Application Description Language

3.10 Unset Values

Database tables regularly contain optional fields. If you retrieve a record from a table with an optional field, and the field does not contain a value, the field is said to contain a null value. The semantics of null values and a null handle are similar but subtly different. A null handle has a value; it simply doesn't point to any object. Programmers often use a null handle to mark an end of a list or an inactive option rather than missing data. Null values, however, have no value at all. They are unset. The ADL supports the concept of unset values primarily to provide a more uniform interface to databases.

The constant UNSET is typeless and represents an unset value. It can be assigned to a variable of any type, used in (==) and (!=) comparisons and put on lists. The examples shown in Figure 3.26 are legal.
Operations with the Constant UNSET
integer answer;

string question;

list record = { "When?" };

any elt;

if ( answer == UNSET )

{

question = "Why";

}

elt = at( 1, record );

if ( elt != UNSET && isString( elt ) )

{

question = elt;

}

record << UNSET;

All uninitialized variables have an unset value. Unset values can appear wherever the constant UNSET can with one exception: the comparison of two values is a run-time error if one or both are unset. You can, however, compare an unset value to the constant UNSET. It is important to distinguish an unset string or list from an empty one. You can append to an empty string or list, but not to an unset one. Unset values can appear in lists, however, and the list append operator ( << ) can append an unset value to a list.

You can use the operator (?var) to test for the existence of an array element and to test if a variable is set.The expression var == UNSET is syntactic sugar for it. Similarly, you can compare array elements with UNSET to determine if they exist. Finally, assigning an array element the constant UNSET is equivalent to calling the operator remove except that it is an error to remove a non-existent element, but you can assign UNSET to one.


AM2 Documentation - 19 NOV 1996

Generated with Harlequin WebMaker