Minimum (NamedArraylist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
 
(13 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Template:NamedArraylist:Minimum subtitle}}
{{Template:NamedArraylist:Minimum subtitle}}
 
This function returns the name (subscript) of the NamedArraylist item that has
<var>Minimum</var> returns the name of the <var>NamedArraylist</var> item that has the minimum 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.
the minimum value after the application of a specified function to each item.
The function that gets applied to each NamedArraylist item, which
<var>Minimum</var> is available in <var class="product">Sirius Mods</var> version 7.3 and later.
you identify in the argument to Minimum, 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..
 
Minimum is available in ''Sirius Mods'' version 7.3 and later.
==Syntax==
==Syntax==
{{Template:NamedArraylist:Minimum syntax}}
{{Template:NamedArraylist:Minimum syntax}}
===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 minimum value after the argument function has been applied. </td></tr>
<td>A string variable to contain the name of the item in <var class="term">nal</var>, the method object <var>NamedArraylist</var>, that has the minimum value as returned by the argument function. </td></tr>
<tr><th>%namrayl</th>
 
<td>A NamedArraylist object. </td></tr>
<tr><th>nal</th>
<tr><th>function</th>
<td>A <var>NamedArraylist</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 objects of the type specified on the ''%narrayl'' declaration and that returns a numeric or string value.
 
<p class="code">As of ''Sirius Mods'' version 7.6, the special identity function, <tt>This</tt>, is the default ''function'' value for the Minimum and Maximum 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>
</p>
<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 <var class="product">Sirius Mods</var> version 7.6, the special identity function, <var>This</var>, is the default ''function'' value for the <var>Minimum</var> and <var>[[Maximum (NamedArraylist function)|Maximum]]</var> methods. See [[Collections#Using the This function as the Maximum parameter|"Using the This function as the Maximum parameter"]].</td></tr>
</table>
</table>
==Usage notes==
==Usage notes==
<ul>
<ul>
<li>If the function applied by Minimum returns string values, Minimum
<li>If <var class="term">itemFunction</var> returns <var>String</var> or <var>Unicode</var> values, <var>Minimum</var> uses the collating sequence of EBCDIC or Unicode, respectively, to determine which item has the least value. If <var class="term">itemFunction</var> returns a numeric type, numeric comparisons are used. See the [[#Examples|"example"]] below.
uses the decimal-equivalent value of the character bytes and determines
 
the number of the item that has the lowest value.
<li>If the values returned by <var class="term">itemFunction</var> for two or more <var>NamedArraylist</var> items are equal, minimum, values, <var>Minimum</var> returns the name of that item which is closest to the beginning of the <var>NamedArraylist</var>.
Therefore, lowercase letters are ranked alphabetically and
 
the minimum lowercase letter is "a";
<li>The <var>[[Maximum (NamedArraylist function)|Maximum]]</var> function is the opposite of the <var>Minimum</var> function.
the uppercase letters are ranked alphabetically and
 
the minimum uppercase letter is "A";
<li>The parameter for <var>Minimum</var> is a method value, not a <var class="product">User Language</var> expression.
"z" ranks lower than all the uppercase letters;
and all letters rank lower than any number.
<li>If one or more NamedArraylist items have equal, minimum, values,
Minimum returns the name of the item that appears closest to the beginning
of the NamedArraylist.
<li>The [[Maximum (NamedArraylist function)|Maximum]] function is the opposite of the Minimum function.
<li>The parameter for Minimum is a method value, not a User Language expression.
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 Minimum parameter.
(say, <code>ToIntegerPower(2)</code>) as the <var>Minimum</var> 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 <var>ToIntegerPower</var>
with the Maximum or Minimum method for an Arraylist.
with the <var>Maximum</var> or <var>Minimum</var> method for an <var>Arraylist</var>.
<li>For an example of the Minimum method for a NamedArraylist,
see [[Maximum (NamedArraylist function)#Examples|NamedArraylist Maximum function example]], and also see [[Collections#Finding collection maxima and minima, and sorting|Finding collection maxima and m
</ul>
</ul>
==Examples==
<ol>
<li>The following fragment uses the special method <var>This</var> (by default);
it shows that the <var>Minimum</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:minimum }
%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:minimum }
%fltAtomWt is namedArraylist of float
%fltAtomWt = new
%fltAtomWt('Li') = 6.948
%fltAtomWt('B') = 10.81
printText {~= %fltAtomWt:minimum }
* Showing that string item type may not be the best if items are numeric:
%strAtomWt is namedArraylist of string len 30
%strAtomWt = new
%strAtomWt('Li') = 6.948
%strAtomWt('B') = 10.81
printText {~= %strAtomWt:minimum }
</nowiki></p>
The result is:
<p class="output">%hit:minimum = Davies
%unicHit:minimum = Simon
%fltAtomWt:minimum = Li
%strAtomWt:minimum = B
</p>
<li>For other examples,
see [[Collections#Finding collection maxima and minima, and sorting|"Finding collection maxima and minima, and sorting"]].
</ol>
==See also==
==See also==
{{Template:NamedArraylist:Minimum footer}}
{{Template:NamedArraylist:Minimum footer}}

Latest revision as of 19:57, 1 November 2012

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


Minimum returns the name of the NamedArraylist item that has the minimum 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.

Minimum is available in Sirius Mods version 7.3 and later.

Syntax

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

Syntax terms

%string A string variable to contain the name of the item in nal, the method object NamedArraylist, that has the minimum 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 function value for the Minimum and Maximum methods. See "Using the This function as the Maximum parameter".

Usage notes

  • If itemFunction returns String or Unicode values, Minimum uses the collating sequence of EBCDIC or Unicode, respectively, to determine which item has the least value. If itemFunction returns a numeric type, numeric comparisons are used. See the "example" below.
  • If the values returned by itemFunction for two or more NamedArraylist items are equal, minimum, values, Minimum returns the name of that item which is closest to the beginning of the NamedArraylist.
  • The Maximum function is the opposite of the Minimum function.
  • The parameter for Minimum 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 Minimum parameter. Example "Maximum/Minimum with local method" shows a way to apply ToIntegerPower with the Maximum or Minimum method for an Arraylist.

Examples

  1. The following fragment uses the special method This (by default); it shows that the Minimum 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:minimum } %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:minimum } %fltAtomWt is namedArraylist of float %fltAtomWt = new %fltAtomWt('Li') = 6.948 %fltAtomWt('B') = 10.81 printText {~= %fltAtomWt:minimum } * Showing that string item type may not be the best if items are numeric: %strAtomWt is namedArraylist of string len 30 %strAtomWt = new %strAtomWt('Li') = 6.948 %strAtomWt('B') = 10.81 printText {~= %strAtomWt:minimum }

    The result is:

    %hit:minimum = Davies %unicHit:minimum = Simon %fltAtomWt:minimum = Li %strAtomWt:minimum = B

  2. For other examples, see "Finding collection maxima and minima, and sorting".

See also