depth

Prev Next

Function Names

depth

Description

The function depth() returns the nesting depth of a specified variable. 1 is returned for all variables not containing any array or structure members. 2 is returned if one level of members, e.g. a simple array or structure without nesting is provided. 3 is returned if further sub-members are specified, and so forth.

The function weight profile provides more detailed weight information for every level in the variable tree. The base variable is level 0, its array and structure members are at level 1, their sub-members at level 2, etc. The value returned is a set containing the weight fore every level found.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

1

Parameters

No.TypeDescription
1
code
variable
:string
Variable name

This variable including all its members and sub-members will be weighed.

Return value

TypeDescription
numeral Depth value

Number of levels. The value returned is at least 1.

Examples

       dim( a[], 10, 0 ); // Level 1
       dim( a[3], 5, 0 ); // Level 2
       structure( a[3,2], { Ha, He, Hi, Ho }, { 1, 2, 3, 4 } ); // Level 3

       echo( "Variable a[]   :  ", depth(a[]), "  The entire variable tree" );
       echo( "Variable a[1]  : ", depth(a[1]), "  Member variable of a[], but has no sub-members" );
       echo( "Variable a[3]  : ", depth(a[3]), "  This one has sub-members" );
       echo( "Variable a[3,2]: ", depth(a[3,2]), "  This variable contains 4 leaf variables" );
       echo( "Variable a[3,2,Ha]: ", depth(a[3,2,Ha]), "  This leaf variable has depth 1 (no further variables)" );

Output

Variable a[]   :  4  The entire variable tree
Variable a[1]  : 1  Member variable of a[], but has no sub-members
Variable a[3]  : 3  This one has sub-members
Variable a[3,2]: 2  This variable contains 4 leaf variables
Variable a[3,2,Ha]: 1  This leaf variable has depth 1 (no further variables)
Try it yourself: Open LIB_Function_depth.b4p in B4P_Examples.zip. Decompress before use.

See also

weight
weight profile