Maximum (NamedArraylist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
 
(21 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<span style="font-size:120%; color:black"><b><section begin=dpl_desc/>Get item that has maximum value<section end=dpl_desc/></b></span>
{{Template:NamedArraylist:Maximum subtitle}}
[[Category:NamedArraylist methods|Maximum function]]
<!--DPL?? Category:NamedArraylist methods|Maximum function: Get item that has maximum value-->
<var>Maximum</var> returns the name of the <var>NamedArraylist</var> item that has the maximum value as returned by a specified function. The function applied to each <var>NamedArraylist</var> item, which you specify with the required <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>, or <var>Unicode</var>) value.
<p>
Maximum is a member of the [[NamedArraylist class]].
</p>
 
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==
==Syntax==
<p class="code">%str = %namrayl:Maximum(function)
{{Template:NamedArraylist:Maximum syntax}}
</p>
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%str</th>
<tr><th>%string</th>
<td>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. </td></tr>
<td>A string variable to contain the name of the item in the indicated <var>NamedArraylist</var> that has the maximum value as returned by the argument function.</td></tr>
<tr><th>%namrayl</th>
<tr><th>nal</th>
<td>A NamedArraylist object. </td></tr>
<td>A <var>NamedArraylist</var> object. </td></tr>
<tr><th>function</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) 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) that operates on objects of the type specified on the <var class="term">nal</var> declaration and that returns an intrinsic 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>
<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>
==Usage Notes==
==Usage notes==
<ul>
<ul>
<li>If the function applied by Maximum returns string values, Maximum
<li>If <var class="term">itemFunction</var> returns <var>String</var> or <var>Unicode</var> values, <var>Maximum</var> uses the collating sequence of EBCDIC or Unicode, respectively, to determine which item has the greatest value. If <var class="term">itemFunction</var> returns a numeric type, numeric comparisons are used. See the second [[#Examples|"example"]] below.
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 &ldquo;z&rdquo;;
the uppercase letters are ranked alphabetically and
the maximum uppercase letter is &ldquo;Z&rdquo;;
&ldquo;z&rdquo; ranks lower than all the uppercase letters;
and all letters rank lower than any number.
<li>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.
<li>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, <tt>ToIntegerPower(2)</tt>) as the Maximum parameter.
Example "[[Maximum (Arraylist function)|Maximum/Minimum with local method]]" shows a way to apply ToIntegerPower
with Maximum for an Arraylist.
<li>The [[Minimum (NamedArraylist function)|Minimum]] function is the opposite of the Maximum function.
</ul>
==Examples==


The following request uses the special method, <tt>This</tt>,
<li>If the values returned by <var class="term">itemFunction</var> for two or more <var>NamedArraylist</var> items are equal, maximum, values, <var>Maximum</var> returns the name of that item which is closest to the beginning of the <var>NamedArraylist</var>.
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 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


%nalist is collection NamedArraylist of longstring
<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 (Arraylist function)#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>.
%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)}
<li><var>Maximum</var> is available in <var class="product">[[Sirius Mods|Sirius Mods]]</var> Version 7.3 and later.
PrintText {~} is item {%nalist:minimum(this)}
</ul>


==Examples==
<ol><li>The following request uses the special method, <var>This</var>, to find the maximum and minimum items in this familiar <var>NamedArraylist</var>.
For more information about using <var>This</var>, see [[Collections#Using the This function as the Maximum parameter|"Using the This function as the Maximum parameter"]].
<p class="code">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 statement|printText]] {~} is item {%nalist:maximum(this)}
  PrintText {~} is item {%nalist:minimum(this)}
end
end
</p>
</p>
 
The result is:
The result is:
<p class="output">%nalist:maximum(this) is item Gilliam
<p class="output">%nalist:maximum(this) is item Gilliam
%nalist:minimum(this) is item Idle
%nalist:minimum(this) is item Idle
</p>
</p>
<li>The following fragment also uses <var>This</var> (by default); it shows that the <var>Maximum</var> value depends on the ordering implied by the intrinsic type returned by the <var class="term">itemFunction</var>:
<p class="code"><nowiki>%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 }
</nowiki></p>
The result is:
<p class="output">%hit:maximum = Simon
%unicHit:maximum = Clapton
%fltAtomWt:maximum = B
%strAtomWt:maximum = Li
</p>
<li>For more examples with <var>Maximum</var> and <var>Minimum</var> for collections, see [[Collections#Finding collection maxima and minima, and sorting|"Finding collection maxima and minima, and sorting"]].
</ol>
==See also==
<ul>
<li>The <var>[[Minimum (NamedArraylist function)|Minimum]]</var> function is the opposite of the <var>Maximum</var> function.
</ul>
{{Template:NamedArraylist:Maximum footer}}

Latest revision as of 17:16, 7 March 2013

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.