Maximum (NamedArraylist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 13: Line 13:
<tr><th>itemFunction</th>
<tr><th>itemFunction</th>
<td>A method value (a method name literal, a method variable, or even a method that returns a method value) of the method that operates on objects of the type specified on the <var class="term">nal</var> declaration and that returns a numeric or string value.
<td>A method value (a method name literal, a method variable, or even a method that returns a method value) of the method that operates on objects of the type specified on the <var class="term">nal</var> declaration and that returns a numeric or string value.
<p>As of <var class="product">"Sirius Mods"</var> Version 7.6, the special identity function, <var>This</var>, is the default <var class="term">itemFunction</var> value for the <var>Maximum</var> and <var>Minimum</var> methods. See [[Collections#Using the This function as the Maximum parameter|"Using the This function as the Maximum parameter"]].</p></td></tr>
<p>As of <var class="product">Sirius Mods</var> Version 7.6, the special identity function, <var>This</var>, is the default <var class="term">itemFunction</var> value for the <var>Maximum</var> and <var>Minimum</var> methods. See [[Collections#Using the This function as the Maximum parameter|"Using the This function as the Maximum parameter"]].</p></td></tr>
</table>
</table>



Revision as of 21:10, 24 May 2011

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


Maximum function returns the name (subscript) of the NamedArraylist item that has the maximum numeric value after the application of a specified function to each item. 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, Longstring, or Unicode) value.

Syntax

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

Syntax terms

%string A string variable to contain the subscript name of the item in the indicated NamedArraylist that has the maximum value after the argument function has been applied.
nal A NamedArraylist object.
itemFunction A method value (a method name literal, a method variable, or even a method that returns a method value) of the method that operates on objects of the type specified on the nal declaration and that returns a numeric or string 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 the function applied by Maximum returns string values, Maximum uses the decimal-equivalent value of the character bytes and determines the number of the item that has the greatest value. Lowercase letters are first ranked alphabetically; then uppercase letters, also ranked alphabetically; finally followed by the numbers; that is: 'a'..'z','A'..'Z',0..9.
  • If two or more NamedArraylist items have equal, maximum, values, Maximum returns the position of the item that appears 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/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. 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.