Ascending and Descending (SortOrder functions)

From m204wiki
Revision as of 20:21, 17 December 2010 by Dme (talk | contribs)
Jump to navigation Jump to search

Create SortOrder object to sort in ascending o

Ascending and Descending are members of the 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

  %sord = [%(sortorder for itemtype):] Ascending(function)
  %sord = [%(sortorder for itemtype):] Descending(function)

Syntax terms

%sord
A SortOrder object variable to contain the new object instance.
%(sortorder for itemtype)
This optional specification of the class and collection item type in parentheses indicates that the method is shared and does not operate on a specific instance.
function
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 function 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 function 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:
        %sord = Descending(&'italic(function))
        %sord = %(sortorder for float):Descending(&'italic(function))
        %sord = %sord:Descending(&'italic(function))
    
  • 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. In order to do this, ee 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 function 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:
        %sord = Descending(this)
        %sord = Descending
    

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