AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
defined (String name [, Object target]) reserved
defined (int index, Object target)  
defined (Pointer target)  
 
Looks for an existing definition, either in the current scope or in target, and returns 1 if the lookup succeeds and 0 otherwise. A single argument that is a String asks defined to look through the current block and all enclosing blocks for a definition of variable name. Two arguments asks whether the object at index in target is defined, or whether target contains a definition of name. A single argument that is a Pointer but not a String (e.g., a Dictionary or Array) is also allowed and simply asks if the object at 0 in target is defined. In other words,
defined(0, target)
and
defined(target)
are equivalent. This last style is often used in loops where a pointer's offset, rather than an integer variable, is being incremented or decremented.
 
 Example:   The program,
import yoix.stdio.*;

if (defined("ptr")) {
    if (defined("total", ptr))
        printf("ptr.total=%d\n", ptr.total);
    else printf("ptr.total is not defined\n");
} else printf("ptr is not defined\n");
shows how you can find out if ptr.total exists, and if so print its value.

The next program

import yoix.*.*;

Dictionary dict[VM@sizeof + 5] = VM;

for (ptr in dict) {
    if (!defined(ptr))
       printf("dict[%d] is not defined\n", ptr@offset);
}
prints something like
dict[10] is not defined
dict[12] is not defined
dict[13] is not defined
dict[14] is not defined
dict[15] is not defined
on standard output, which identifies the five unused elements in dictionary dict. Notice how the declaration of dict was used to copy VM into a new dictionary with exactly five extra elements.
 
 Return:   int

 

Yoix is a registered trademark of AT&T Inc.