Ascending and Descending (SortOrder functions): Difference between revisions

From m204wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
{{Template:SortOrder:Ascending and Descending subtitle}}
{{Template:SortOrder:Ascending and Descending subtitle}}


These shared methods create a new instance of the SortOrder class.
These shared methods create a new instance of the <var>SortOrder</var> class.
The ordering direction of the new instance is given by the constructor name:
The ordering direction of the new instance is given by the constructor name:
Ascending is low-to-high; Descending is high-to-low.
<var>Ascending</var> is low-to-high; <var>Descending</var> is high-to-low.


The sorting key of the new instance is specified by the input parameter
The sorting key of the new instance is specified by the input parameter
Line 9: Line 9:
This parameter is a function that gets
This parameter is a function that gets
applied to each item in the collection that is being sorted, and it must be
applied to each item in the collection that is being sorted, and it must be
a method that operates on the item type and returns a User Language intrinsic
a method that operates on the item type and returns a <var class="product">User Language</var> intrinsic
datatype (Float, String, Longstring, or Unicode) value.
datatype (<var>Float</var>, <var>String</var>, <var>Longstring</var>, or <var>Unicode</var>) value.
===Ascending/Descending syntax===
 
==Ascending/Descending syntax==
{{Template:SortOrder:Ascending syntax}}
{{Template:SortOrder:Ascending syntax}}
{{Template:SortOrder:Descending syntax}}
{{Template:SortOrder:Descending syntax}}


  %sord = [%(sortorder for itemtype):] Ascending(function)
  %sord = [%(sortorder for itemtype):] Descending(function)
===Syntax terms===
===Syntax terms===
<dl>
<table class="syntaxTable">
<dt><i>%sord</i>
<tr><th>%sortOrder</th>
<dd>A SortOrder object variable to contain the new object instance.
<td>A <var>SortOrder</var> object variable to contain the new object instance. </td></tr>
<dt><i>%(sortorder for itemtype)</i>
<tr><th><var>%(SortOrder For</var> itemtype)</th>
<dd>This optional specification of the class and collection item type
<td>This optional specification of the class in parentheses indicates that the method is shared and does not operate on a specific instance. If you use this option, however, you must include the collection item type to which the selection expression will be applied, like this: <code>%(SortOrder For <i>itemtype</i>):</code> </td></tr>
in parentheses indicates
<tr><th>itemFunction</th>
that the method is shared and does not operate on a specific instance.
<td>A method value (a method name literal, a method variable, a class <var>Variable</var>,
<dt><i>function</i>
<dd>A method value (a method name literal, a method variable, a class Variable,
or even a method that returns a method value) for a method
or even a method that returns a method value) for a method
that operates on objects of the type specified on the
that operates on objects of the type specified on the
declaration of the collection being sorted, and that returns a numeric or
declaration of the collection being sorted, and that returns a numeric or
string value.
string value.  
 
<br>
The default ''function'' value as of ''Sirius Mods'' version 7.6
The default <var class="term">itemFunction</var> value as of <var class="product">Sirius Mods</var> version 7.6 is the special value <var>This</var>, described further in the "Usage Notes," below. </td></tr>
is the special value <tt>This</tt>,
</table>
described further in the &ldquo;Usage Notes,&rdquo; below.


</dl>
==Usage Notes==
===Usage Notes===
<ul>
<ul>
<li>For more information about the ''function'' parameter,
<li>For more information about the <var class="term">itemFunction</var> parameter,
see [[SortOrder class#Specifying a SortOrder's sort key method|Specifying a SortOrder's sort key method]].
see [[SortOrder class#Specifying a SortOrder's sort key method|"Specifying a SortOrder's sort key method"]].
<li>Ascending and Descending are constructors and as such can be called with
<li><var>Ascending</var> and <var>Descending</var> are constructors and as such can be called with
no method object, with an explicit class name, or with an object variable,
no method object, with an explicit class name, or with an object variable,
even if that object is null:
even if that object is null:
<pre>
<p class="code">%sortOrder = Descending(<i>itemFunction</i>)
    %sord = Descending(&'italic(function))
%sortOrder = %(SortOrder for float):Descending(<i>itemFunction</i>)
    %sord = %(sortorder for float):Descending(&'italic(function))
%sortOrder = %sortOrder:Descending(<i>itemFunction</i>)
    %sord = %sord:Descending(&'italic(function))
</p>
</pre>
<li>The parameter in the <var>Ascending</var> and <var>Descending</var> methods is a method value, not a <var class="product">User Language</var> expression,
<li>The Ascending or Descending parameter is a method value, not a User Language expression,
and you may not specify a function that itself has an argument.
and you may not specify a function that itself has an argument.
In order to do this, see the [[SortOrder class#xmplocal|example using a Local function]], which shows a way to apply such a function
In order to do this, see the [[SortOrder class#xmplocal|example using a Local function]], which shows a way to apply such a function in a sort.
in a sort.
<li>As of <var class="product">Sirius Mods</var> version 7.6, the
<li>As of ''Sirius Mods'' version 7.6, the
default <var>SortOrder</var> <var class="term">itemFunction</var> value is <var>This</var>, a
default SortOrder ''function'' value is <tt>This</tt>, a
method value that is valid for <var class="product">User Language</var> [[Intrinsic classes#Two generic intrinsic classes: string and numeric|intrinsic]] method objects only.
method value that is valid for User Language intrinsic method objects only.
The identity method <var>This</var> returns the value of the
The identity method <tt>This</tt> returns the value of the
method object to which it is applied.
method object to which it is applied.


The following statements are therefore equivalent:
The following statements are therefore equivalent:
<pre>
<p class="code">%sortOrder = Descending(this)
    %sord = Descending(this)
%sortOrder = Descending
    %sord = Descending
</p>
</pre>
'''Note:'''
'''Note:'''
Using the default SortOrder above on a non-intrinsic method object
Using the default <var>SortOrder</var> above on a non-intrinsic method object
produces a compilation error.
produces a compilation error.
</ul>
</ul>


==See also==
{{Template:SortOrder:Ascending and Descending footer}}
{{Template:SortOrder:Ascending and Descending footer}}
[[Category:SortOrder methods]]

Revision as of 20:50, 29 June 2011

Create SortOrder object to sort in ascending or descending order (SortOrder class)


These shared methods create a new instance of the SortOrder class. The ordering direction of the new instance is given by the constructor name: Ascending is low-to-high; Descending is high-to-low.

The sorting key of the new instance is specified by the input parameter to the constructor. This parameter is a function that gets applied to each item in the collection that is being sorted, and it must be a method that operates on the item type and returns a User Language intrinsic datatype (Float, String, Longstring, or Unicode) value.

Ascending/Descending syntax

%sortOrder = [%(SortOrder For itemType):]Ascending[( [itemFunction])]

%sortOrder = [%(SortOrder For itemType):]Descending[( [itemFunction])]

Syntax terms

%sortOrder A SortOrder object variable to contain the new object instance.
%(SortOrder For itemtype) This optional specification of the class in parentheses indicates that the method is shared and does not operate on a specific instance. If you use this option, however, you must include the collection item type to which the selection expression will be applied, like this: %(SortOrder For itemtype):
itemFunction A method value (a method name literal, a method variable, a class Variable,

or even a method that returns a method value) for a method that operates on objects of the type specified on the declaration of the collection being sorted, and that returns a numeric or string value.

The default itemFunction value as of Sirius Mods version 7.6 is the special value This, described further in the "Usage Notes," below.

Usage Notes

  • For more information about the itemFunction parameter, see "Specifying a SortOrder's sort key method".
  • Ascending and Descending are constructors and as such can be called with no method object, with an explicit class name, or with an object variable, even if that object is null:

    %sortOrder = Descending(itemFunction) %sortOrder = %(SortOrder for float):Descending(itemFunction) %sortOrder = %sortOrder:Descending(itemFunction)

  • The parameter in the Ascending and Descending methods is a method value, not a User Language expression, and you may not specify a function that itself has an argument. In order to do this, see the example using a Local function, which shows a way to apply such a function in a sort.
  • As of Sirius Mods version 7.6, the default SortOrder itemFunction value is This, a method value that is valid for User Language intrinsic method objects only. The identity method This returns the value of the method object to which it is applied. The following statements are therefore equivalent:

    %sortOrder = Descending(this) %sortOrder = Descending

    Note: Using the default SortOrder above on a non-intrinsic method object produces a compilation error.

See also