structure, structure protect

Prev Next

Function Names

structure, structure protect

Description

The function structure defines a structure with members and their initial values provided directly. Already existing variable members will be eliminated. The function structure project will also apply the protection settings on all member variables created. See description for function protect() for details. It may be useful to choose protection setting limited access in order to avoid accidental type changes on the structure members.

Impact on base variables: The base variable values remain unaffected. These functions affect the members only.

Call as: procedure

Restrictions

Indirect parameter passing is disabled

Parameter count

structure: 3, 6, 9, etc.; structure protect: 4, 7, 10, etc.

Parameters

No.TypeDescription
1
input
string Protection setting

Applicable to structure protect only. The supported protection settings are defined in the description for the function protect().

1, 4, ... or 2, 5, ...
code
variable
:string
Variable name

The structure will be built on the specified variable. Member variables of existing arrays and structures are allowed so you can build more complex data structures.

2, 5, ... or 3, 6, ...
input
set Member names

If a simple set is provided (no nested elements), then a one-dimensional structure will be built. Nested paramter sets will create nested structures.

Default value: text
2, 5, ... or 3, 6, ...
input
set Initial values

If a simple set is provided (no nested elements), then a one-dimensional array will be built. Nested paramter sets will create nested arrays. The set must have the same structure (attention to nesting) as in the previous function parameter for the corresponding paramter names.

Default value: text

Examples

       structure( sizes[], { Cat, Mouse, Ant }, {medium, small, tiny} );
       echo( sizes[Cat ]);
       echo( sizes[Mouse]);
       echo( sizes[Ant]);
       echo;
       structure( a[], { a,b,c,{d,e},f}, { 1,2,3,{4,5},6 }  );

       // Builds a[a,b,c,f]  = { 1,2,3,6 }
       // Builds a[c,d] and a[c,e] with 4 and 5

       see ( a[] );

Output

medium
small
tiny

a[]                     [Void]                     (void,full access)
a                       1  "1"                     (numeral,full access)
b                       2  "2"                     (numeral,full access)
c                       3  "3"                     (numeral,full access)
  d                     4  "4"                     (numeral,full access)
  e                     5  "5"                     (numeral,full access)
f                       6  "6"                     (numeral,full access)

Try it yourself: Open LIB_Function_structure.b4p in B4P_Examples.zip. Decompress before use.

See also

array
array protect