System.Length - Manhunter07/MFL GitHub Wiki

Declaration

function Length(Value: System.Struct): System.PosInt = \built-in\

Description

The Length function in the System package allows a memory-abstract size determination of a value. It retruns the member count of an value passed uppon the Value parameter. The parameter accepts any value supported by the Struct type. This includes Strings, Arrays or Records. The function returns a positive (0 or greater) numeric integer value (supported by System.PosInt).

The following values will be returned for the different input data-types:

  • For strings, this function will return the character count
  • For arrays, this function will return the element count
  • For records, this function will return the field count

The function does not count recursively. Thus, if an array contains an element that's either an empty or a very long array itself, this always counts as 1 to the result. If you want to find out the total amount of elements/fields including the sub elements/fields of an array/record you have to flatten it first using the Flatten function:

Length([122, "Foo", ["Bar", "Boom"], 4.5]) \returns 3\
Length(Flatten([122, "Foo", ["Bar","Boom"], 4.5]) \returns 5\

Please keep in mind that because of abstraction, there is no way to determine the memory consumed by a value in MFL.

See also