Maximum (Arraylist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
 
(35 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{Template:Arraylist:Maximum subtitle}}
{{Template:Arraylist:Maximum subtitle}}
<var>Maximum</var> returns the number of the <var>Arraylist</var> item that has the maximum numeric value after the application of a specified function to each item.  The function that gets applied to each <var>Arraylist</var> item, which you identify using the <var class="term">itemFunction</var> argument, must be a method that operates on the item type and returns a <var class="product">User Language</var> [[Intrinsic classes|intrinsic]] datatype (<var>Float</var>, <var>String</var>, <var>Longstring</var>, or <var>Unicode</var>) value.


This function returns the number of the <var>Arraylist</var> item that has the maximum
numeric value after the application of a specified function to each item.
The function that gets applied to each <var>Arraylist</var> item, which
you identify in the argument to <var>Maximum</var>, must be a method
that operates on the item type and returns a User Language intrinsic
datatype (<var>Float</var>, <var>String</var>, <var>Longstring</var>, or <var>Unicode</var>) value.
The system intrinsic classes are discussed in "[[Intrinsic classes]]".
Local methods are discussed in [[??]] refid=localm..
<var>Maximum</var> is available in ''Sirius Mods'' version 7.3 and later.
==Syntax==
==Syntax==
{{Template:Arraylist:Maximum syntax}}
{{Template:Arraylist:Maximum syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th><i>%num</i></th>
<tr><th>%number</th>
<td>A numeric variable to contain the item number of the item in the indicated <var>Arraylist</var> that has the maximum value after the argument function is applied. </td></tr>
<td>A numeric variable to return the item number of the item in the indicated <var>Arraylist</var> that has the maximum value after the argument function is applied.</td></tr>
<tr><th><i><var class="term">al</var></i></th>
 
<td>An <var>Arraylist</var> object. </td></tr>
<tr><th>al</th>
<tr><th><i>function</i></th>
<td>An <var>Arraylist</var> object.</td></tr>
<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 items of the type specified on the ''<var class="term">al</var>'' 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 <var>Maximum</var> and Minimum methods. See "[[Collections#Using the This function as the Maximum parameter|Using the This function as the Maximum parameter]]".</td></tr>
<tr><th>itemFunction</th>
<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 items of the type specified on the <var class="term">al</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"]] for more information.</p></td></tr>
</table>
</table>
==Usage notes==
==Usage notes==
<ul>
<ul>
<li>If the function applied by <var>Maximum</var> returns string values, <var>Maximum</var>
<li>If the function applied by <var>Maximum</var> returns string values, <var>Maximum</var> 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: <code>'a'..'z','A'..'Z',0..9</code>.
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.
<li>If two or more <var>Arraylist</var> items have equal, maximum, values,
<var>Maximum</var> returns the position of the item that appears closest to the beginning
of the <var>Arraylist</var>.
<li>The parameter for <var>Maximum</var> is a method value, not a User Language expression.
That is, you cannot provide a function that itself has an argument
(say, <tt>ToIntegerPower(2)</tt>) as the <var>Maximum</var> parameter.
The example of "[[Maximum (Arraylist function)#Maximum/Minimum with local method|Maximum/Minimum with local method]]" shows a way to apply ToIntegerPower
with <var>Maximum</var>.
<li>The [[Minimum (Arraylist function)|Minimum]] function is the opposite of the <var>Maximum</var> function.
</ul>
==Examples==
===<var>Maximum</var> and Minimum using Count function===
In the following example, the <var>Maximum</var> and Minimum methods first
apply the <var>Stringlist</var> [[Count (Stringlist function)|Count]] function, then
return the position of the <var>Arraylist</var> item
<var>Stringlist</var> that has the most items and the one that has the fewest.
The <var>Stringlist</var> [[List (Stringlist function)|List]] function simplifies the construction of the lists.
<pre style="xmp">
    b
    %list1 is object stringlist
    %list2 is object stringlist
    %list3 is object stringlist


    %list1 = List('the', 'quick', 'brown')
<li>If two or more <var>Arraylist</var> items have equal, maximum, values, <var>Maximum</var> returns the position of the item that appears closest to the beginning of the <var>Arraylist</var>.
    %list2 = List('fox', 'jumped', 'over', 'the')
    %list3 = List('lazy', 'dog', 'yesterday', 'two', 'times')


    <var class="term">al</var> is collection arraylist of object stringlist
<li>The parameter for <var>Maximum</var> is a method value, not a <var class="product">User Language</var> expression. That is, you cannot provide a function that itself has an argument (say, <code>ToIntegerPower(2)</code>) as the <var>Maximum</var> parameter.  The [[#Maximum and Minimum with local method|"Maximum and Minimum with local method"]] example shows a way to apply <var>[[ToIntegerPower and ToPower (Float functions)|ToIntegerPower]]</var> with <var>Maximum</var>.
    <var class="term">al</var> = List(%list1, %list2, %list3)


    PrintText {~} is {al:maximum(count)}
<li><var>Maximum</var> is available in <var class="product">[[Sirius Mods|Sirius Mods]]</var> Version 7.3 and later.
    PrintText {~} is {al:minimum(count)}
</ul>
    end
</pre>


The result is:
==Examples==
<pre style="xmp">
    <var class="term">al</var>:maximum(count) is 3
    <var class="term">al</var>:minimum(count) is 1
</pre>
===<var>Maximum</var>/Minimum with local method===
The local method used with <var>Maximum</var> in the following request
applies the
ToIntegerPower method, which (because it requires its own argument)
the syntax of <var>Maximum</var> does not allow as a parameter.
<pre style="xmp">
    b
    %alist is collection arraylist of float
    %alist = List(10, -11, 0, 11)


    local function (float):Squared is float
====Maximum and Minimum using Count function====
      return %this:toIntegerPower(2)
In the following example, the <var>Maximum</var> and <var>Minimum</var> functions first apply the <var>Stringlist</var> <var>[[Count (Stringlist function)|Count]]</var> function, then return the position of the <var>Arraylist</var> item <var>Stringlist</var> that has the most items and the one that has the fewest.  The <var>Stringlist</var> <var>[[List (Stringlist function)|List]]</var> function simplifies the construction of the lists.
    end function
<p class="code">begin
  %list1 is object stringlist
  %list2 is object stringlist
  %list3 is object stringlist
  %list1 = List('the', 'quick', 'brown')
  %list2 = List('fox', 'jumped', 'over', 'the')
  %list3 = List('lazy', 'dog', 'yesterday', 'two', 'times')
  al is collection arraylist of object stringlist
  al = List(%list1, %list2, %list3)
  [[PrintText statement|printText]] {~} is {al:maximum(count)}
  printText {~} is {al:minimum(count)}
end
</p>


    PrintText {~} is {%alist:maximum(Squared)}
The result is:
    PrintText {~} is {%alist:minimum(Squared)}
<p class="output">al:maximum(count) is 3
al:minimum(count) is 1
</p>


    end
====Maximum and Minimum with local method====
</pre>
The local method used with <var>Maximum</var> in the following request applies <var>[[ToIntegerPower and ToPower (Float functions)|ToIntegerPower]]</var>, which (because it requires its own argument) the syntax of <var>Maximum</var> does not allow as a parameter.
<p class="code">begin
  %alist is collection arraylist of float
  %alist = List(10, -11, 0, 11)
  local function (float):Squared is float
      return %this:toIntegerPower(2)
  end function
  printText {~} is {%alist:maximum(Squared)}
  printText {~} is {%alist:minimum(Squared)}
end
</p>


The result is:
The result is:
<pre style="xmp">
<p class="output">%alist:maximum(Squared) is 2
    <var class="term">al</var>:maximum(Squared) is 2
%alist:minimum(Squared) is 3
    <var class="term">al</var>:minimum(Squared) is 3
</p>
</pre>
 
Although applying the local method above to item 2 and item 4 produces the same value, <var>Maximum</var> returns the item that is closer to the beginning of the <var>Arraylist</var>.


Although applying the local method above to item 2 and item 4 produces the same
value, <var>Maximum</var> returns the item that is closer to the beginning of the arraylist.
</ol>
==See also==
==See also==
<ul><li><var>[[Minimum (Arraylist function)|Minimum]]</var> is the opposite of the <var>Maximum</var> function.</ul>
{{Template:Arraylist:Maximum footer}}
{{Template:Arraylist:Maximum footer}}

Latest revision as of 16:12, 1 November 2012

Get number of maximum item (Arraylist class)

Maximum returns the number of the Arraylist item that has the maximum numeric value after the application of a specified function to each item. The function that gets applied to each Arraylist item, which you identify using the 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

%number = al:Maximum[( [itemFunction])]

Syntax terms

%number A numeric variable to return the item number of the item in the indicated Arraylist that has the maximum value after the argument function is applied.
al An Arraylist object.
itemFunction 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 items of the type specified on the al 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" for more information.

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 Arraylist items have equal, maximum, values, Maximum returns the position of the item that appears closest to the beginning of the Arraylist.
  • 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

Maximum and Minimum using Count function

In the following example, the Maximum and Minimum functions first apply the Stringlist Count function, then return the position of the Arraylist item Stringlist that has the most items and the one that has the fewest. The Stringlist List function simplifies the construction of the lists.

begin %list1 is object stringlist %list2 is object stringlist %list3 is object stringlist %list1 = List('the', 'quick', 'brown') %list2 = List('fox', 'jumped', 'over', 'the') %list3 = List('lazy', 'dog', 'yesterday', 'two', 'times') al is collection arraylist of object stringlist al = List(%list1, %list2, %list3) printText {~} is {al:maximum(count)} printText {~} is {al:minimum(count)} end

The result is:

al:maximum(count) is 3 al:minimum(count) is 1

Maximum and Minimum with local method

The local method used with Maximum in the following request applies ToIntegerPower, which (because it requires its own argument) the syntax of Maximum does not allow as a parameter.

begin %alist is collection arraylist of float %alist = List(10, -11, 0, 11) local function (float):Squared is float return %this:toIntegerPower(2) end function printText {~} is {%alist:maximum(Squared)} printText {~} is {%alist:minimum(Squared)} end

The result is:

%alist:maximum(Squared) is 2 %alist:minimum(Squared) is 3

Although applying the local method above to item 2 and item 4 produces the same value, Maximum returns the item that is closer to the beginning of the Arraylist.

See also

  • Minimum is the opposite of the Maximum function.