Parameter sets

Prev Next

Parameter Sets

Parameter sets is be considered as the sixth Basic Data Type which allows to hold 0, 1 or more elements. Each element is again a value of any of the six Data Types, including nested parameter sets. In the program code, sets can be defined with any number of values or expressions inside braces { } and separated with commas. Nested parameter sets are supported.

Number of elements At least zero (empty set)
Empty sets Empty parameter sets { } are not the same as blank or void values
Mixed data types A parameter set may contain data of different types, e.g. { 1, Abc, true, date(31.12.2020) }
Nesting Parameter sets support nesting, e.g. { { 1, 2 }, { 3, 4 }, 5 }
Nested empty sets Nested empty sets are allowed. E.g. { {} } is not the same as { } or { { {} } }.
Sequence of elements The sequence of elements is preserved, i.e. {a,b,c,d} and {d,c,b,a} are different.
Comparing them with '=' returns true (ordering does not care), but with '==' returns false (elements must be in same order).
Mulitple identical elements Parameter sets may contain multiple identical elements, e.g. { a, b, a, a, c, c }. You can use the trim() function to eliminate duplicates.
Embedding A paramter set can be embedded into another parameter set, e.g. a[] = {1,2}; b[] = {a[]};
Indexing Parameter Sets One element can be extracted by indexing. 1st element begins wtih 0. Example: a[] = {a,b,c,d}{1}; Here, the 1st element is accessed, a[] gets value 'b'.
Negative indexing Negative indexing supported here. a[] = { a,b,c,d,e }{-2} assigns 'd' to a[].
Slicing Parameter Sets Specify multiple index values and ranges to extract subsets.
Arithmetics A broad range of arithmetic operators are available to manipulate parameter sets, for example intersections and unions.

  a[] = { 1, a, 2, {b,c}, true, date(today) };
  echo( a[], " / ", type(a[]) );
  echo( "First element: ", a[]{0}, " and last element: ", a[]{1} );
{1,'a',2,{'b','c'},true,'2024-07-14'} / parameter set
First element: 1 and last element: a
Try it yourself: Open LAN_Features_data_types_parameter_sets.b4p in B4P_Examples.zip. Decompress before use.