Maximum (NamedArraylist function)

From m204wiki
Jump to navigation Jump to search

Name of item with maximum value or maximum value of function applied to items (NamedArraylist class)


Maximum returns the name of the NamedArraylist item that has the maximum value as returned by a specified function. The function applied to each NamedArraylist item, which you specify with the required itemFunction argument, must be a method that operates on the item type and returns a User Language intrinsic datatype (Float, String, or Unicode) value.

Syntax

%string = nal:Maximum[( [itemFunction])]

Syntax terms

%string A string variable to contain the name of the item in the indicated NamedArraylist that has the maximum value as returned by the argument function.
nal A NamedArraylist object.
itemFunction A method value (a method name literal, a method variable, or even a method that returns a method value) that operates on objects of the type specified on the nal declaration and that returns an intrinsic value.

As of Sirius Mods Version 7.6, the special identity function, This, is the default itemFunction value for the Maximum and Minimum methods. See "Using the This function as the Maximum parameter".

Usage notes

  • If itemFunction returns String or Unicode values, Maximum uses the collating sequence of EBCDIC or Unicode, respectively, to determine which item has the greatest value. If itemFunction returns a numeric type, numeric comparisons are used. See the second "example" below.
  • If the values returned by itemFunction for two or more NamedArraylist items are equal, maximum, values, Maximum returns the name of that item which is closest to the beginning of the NamedArraylist.
  • The parameter for Maximum is a method value, not a User Language expression. That is, you cannot provide a function that itself has an argument (say, ToIntegerPower(2)) as the Maximum parameter. The "Maximum and Minimum with local method" example shows a way to apply ToIntegerPower with Maximum.
  • Maximum is available in Sirius Mods Version 7.3 and later.

Examples

  1. The following request uses the special method, This, to find the maximum and minimum items in this familiar NamedArraylist. For more information about using This, see "Using the This function as the Maximum parameter".

    begin %nalist is collection NamedArraylist of longstring %nalist = new %nalist:useDefault = true %nalist('Idle') = 'Eric' %nalist('Cleese') = 'John' %nalist('Gilliam') = 'Terry' %nalist('Pallin') = 'Michael' %nalist('Chapman') = 'Graham' printText {~} is item {%nalist:maximum(this)} PrintText {~} is item {%nalist:minimum(this)} end

    The result is:

    %nalist:maximum(this) is item Gilliam %nalist:minimum(this) is item Idle

  2. The following fragment also uses This (by default); it shows that the Maximum value depends on the ordering implied by the intrinsic type returned by the itemFunction:

    %hit is namedArraylist of string len 30 %hit = new %hit('Clapton') = 'Layla' %hit('Davies') = 'All Day and All of the Night' %hit('Simon') = '50 Ways to Leave Your Lover' printText {~= %hit:maximum } %unicHit is namedArraylist of unicode %unicHit = new %unicHit('Clapton') = 'Layla' %unicHit('Davies') = 'All Day and All of the Night' %unicHit('Simon') = '50 Ways to Leave Your Lover' printText {~= %unicHit:maximum } %fltAtomWt is namedArraylist of float %fltAtomWt = new %fltAtomWt('H') = 1.008 %fltAtomWt('Li') = 6.948 %fltAtomWt('B') = 10.81 printText {~= %fltAtomWt:maximum } * Showing that string item type may not be the best if items are numeric: %strAtomWt is namedArraylist of string len 30 %strAtomWt = new %strAtomWt('H') = 1.008 %strAtomWt('Li') = 6.948 %strAtomWt('B') = 10.81 printText {~= %strAtomWt:maximum }

    The result is:

    %hit:maximum = Simon %unicHit:maximum = Clapton %fltAtomWt:maximum = B %strAtomWt:maximum = Li

  3. For more examples with Maximum and Minimum for collections, see "Finding collection maxima and minima, and sorting".

See also

  • The Minimum function is the opposite of the Maximum function.