<sort [flags] $var [ICASE|NUM] [DESC|ASC] [$var2 ...]>
sort function takes one or more variable arguments to be
sorted together. If only one variable is given, the return value is
$ret. Otherwise (more than one variable),
the variables are sorted in place, and are treated like the columns of
a table to be sorted by rows. The first variable is the primary key
to order by. Rows that compare the same for this variable are sorted
by the next variable; if the second's values are identical then the
third is compared, etc. If all variables' values compare equal for a
given pair of rows, the original relative row order is preserved.
In version 6 and later, string comparisons use the current apicp
stringcomparemode setting (here).
Several flags may appear after each variable, and apply only to the immediately preceding variable:
DESCSort this variable in descending order, instead of the default ascending order.
ASCSort this variable in ascending order, the default.
ICASEIgnore case when sorting this variable, and sort it alphabetically if it's non-
varchar. Thus "
Norway" is equal to "
norway" with this flag, and the integer value
123is less than
NUMSort numerically: the variable's values are treated as numbers (floating point). This is useful for sorting a
varcharvariable whose values are numbers, which would otherwise be sorted alphabetically.
In addition, there are several flags that may be given immediately before the first variable, as overall flags:
SHORTESTSort the shortest variable's number of values. Ideally, all variables given to
<sort>should have the same number of values, so that a "row" of values across the variables is never broken up. However, if one or more variables are shorter than others, this could cause a "gap" to appear in the shorter variables' arrays (e.g. if the last row became sorted first, there would be no last-row value for the short variables to replace the first).
SHORTEST flag set, these gaps are avoided by
only sorting the first N values, where N is the number of
values of the shortest variable. Later values are unsorted.
Prior to version 5.01.1189552000 20070911, this was the default.
In later versions,
LONGEST is the default.
LONGESTSort the longest variable's number of values. The problem of unequal length variables is handled by sorting all rows, and allowing gaps to appear in shorter variables as needed. These gaps - when they are "internal" or between pre-existing values - are populated with default/empty values. Thus, a short variable may end up with extra values after the
<sort>(but not necessarily as many as the longest var). In version 5.01.1189552000 20070911 and later,
LONGESTis the default.
SHORTEST behavior is needed as a default for
some reason, it can be restored by editing
setting [Texis] Default Vortex Sort Shortest to a non-zero
value. Note that this setting is applied at compile-time only.
sort returns the sorted list in
$ret if one variable is given;
otherwise it returns nothing and the variables are sorted in place.
<$colors = red orange yellow green blue violet>
<$num = "FF0000" "FFA500" "FFFF00" "00FF00" "0000FF" "EE82EE">
<sort $num DESC $colors>
<LOOP $colors $num>
The output, sorted by descending order of color values (e.g. brightness):
sort function was added Aug. 23 1996. The
LONGEST flags were added in
version 5.01.1189552000 20070911.
All variables given to
sort should have the same number of
values. If not, some values may be unsorted, or some variables may
have additional values inserted. See the
In version 6 and later, string comparisons use the current apicp stringcomparemode setting (here).
This is one of the few functions in Vortex that modifies its arguments
$&var reference syntax.