/*
 * File: defined_sizeof.txt
 * ------------------------
 */

/* If a variable has an intrinsic value, it is said to be defined. The function
   defined returns true in that case. */

if (defined(a)) {
    wln("a is defined");
}
else {
    wln("a is not defined");
}

a = 5;
if (defined(a)) {
    wln("a is defined");
}
else {
    wln("a is not defined");
}

/* A variable can have sub-variables without being defined itself. */
b.pos.x = 3;
b.pos.y = 7;
b[1] = 14;
b[2] = 37;
if (defined(b)) {
    wln("b is defined");
}
else {
    wln("b is not defined");
}

/* sizeof returns a variable's number of direct sub-variables. */
wln("b has " + tostring(sizeof(b)) + " sub-variables.");
wln("b.pos has " + tostring(sizeof(b.pos)) + " sub-variables.");

/* If you for some reason want to "undefine" a variable but keep its sub-
   variables (and therefore can't use delete), just assign an undefined variable
   to it. null and nil aren't reserved words in JAIL, but if you keep them
   undefined, they can be used for this very purpose. */
a = null;
if (defined(a)) {
    wln("a is defined");
}
else {
    wln("a is not defined");
}

