Maximum (NamedArraylist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
mNo edit summary
Line 9: Line 9:
datatype (Float, String, Longstring, or Unicode) value.
datatype (Float, String, Longstring, or Unicode) value.


The system intrinsic classes are discussed in "[[Intrinsic classes]]".
The system intrinsic classes are discussed in [[Intrinsic classes|"Intrinsic classes"]].
Local methods are discussed in [[??]] refid=localm..
Local methods are discussed in [[??]] refid=localm..


Line 24: Line 24:
<td>A method value (a method name literal, a method variable, or even a method that returns a method value) for a method that operates on objects of the type specified on the ''%narrayl'' 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) for a method that operates on objects of the type specified on the ''%narrayl'' declaration and that returns a numeric or string value.


As of ''Sirius Mods'' version 7.6, the special identity function, <tt>This</tt>, is the default ''function'' value for the Maximum and Minimum methods. See "[[Collections#Using the This function as the Maximum parameter|Using the This function as the Maximum parameter]]".</td></tr>
As of ''Sirius Mods'' version 7.6, the special identity function, <tt>This</tt>, is the default ''function'' value for the Maximum and Minimum methods. See [[Collections#Using the This function as the Maximum parameter|"Using the This function as the Maximum parameter"]].</td></tr>


</table>
</table>
Line 44: Line 44:
That is, you cannot provide a function that itself has an argument
That is, you cannot provide a function that itself has an argument
(say, <tt>ToIntegerPower(2)</tt>) as the Maximum parameter.
(say, <tt>ToIntegerPower(2)</tt>) as the Maximum parameter.
Example "[[Maximum (Arraylist function)|Maximum/Minimum with local method]]" shows a way to apply ToIntegerPower
Example [[Maximum (Arraylist function)|"Maximum/Minimum with local method"]] shows a way to apply ToIntegerPower
with Maximum for an Arraylist.
with Maximum for an Arraylist.
<li>The [[Minimum (NamedArraylist function)|Minimum]] function is the opposite of the Maximum function.
<li>The [[Minimum (NamedArraylist function)|Minimum]] function is the opposite of the Maximum function.
Line 52: Line 52:
The following request uses the special method, <tt>This</tt>,
The following request uses the special method, <tt>This</tt>,
to find the maximum and minimum items in this familiar NamedArraylist.
to find the maximum and minimum items in this familiar NamedArraylist.
For more information about using <tt>This</tt>, see [[Collections#Using the This function as the Maximum parameter|Using the This function as the Maximum parameter]].
For more information about using <tt>This</tt>, see [[Collections#Using the This function as the Maximum parameter|"Using the This function as the Maximum parameter"]].
For more examples with Maximum and Minimum for collections, see [[Collections#Finding collection maxima and minima, and sorting|Finding collection maxima and minima, and sorting]].
For more examples with Maximum and Minimum for collections, see [[Collections#Finding collection maxima and minima, and sorting|"Finding collection maxima and minima, and sorting"]].
<p class="code">b
<p class="code">b



Revision as of 22:23, 2 March 2011

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


This 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 that gets applied to each NamedArraylist item, which you identify in the argument to Maximum, must be a method that operates on the item type and returns a User Language intrinsic datatype (Float, String, Longstring, or Unicode) value.

The system intrinsic classes are discussed in "Intrinsic classes". Local methods are discussed in ?? refid=localm..

Maximum is available in Sirius Mods version 7.3 and later.

Syntax

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

Syntax terms

%str 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.
%namrayl A NamedArraylist object.
function A method value (a method name literal, a method variable, or even a method that returns a method value) for a method that operates on objects of the type specified on the %narrayl declaration and that returns a numeric or string value. As of Sirius Mods version 7.6, the special identity function, This, is the default function 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. Therefore, lowercase letters are ranked alphabetically and the maximum lowercase letter is "z"; the uppercase letters are ranked alphabetically and the maximum uppercase letter is "Z"; "z" ranks lower than all the uppercase letters; and all letters rank lower than any number.
  • If two or more NamedArraylist items have equal, maximum, values, Maximum returns the name 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. Example "Maximum/Minimum with local method" shows a way to apply ToIntegerPower with Maximum for an Arraylist.
  • The Minimum function is the opposite of the Maximum function.

Examples

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". For more examples with Maximum and Minimum for collections, see "Finding collection maxima and minima, and sorting".

b %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

See also