procedure sortff: sort on multiple fields procedure sortgen: generate by different sorting orders procedure sortt: sort to produce list of records
link sort
September 10, 1998; Bob Alexander, Richard L. Goerwitz, and Ralph E. Griswold
This file is in the public domain.
isort(x, p) customized sort in which procedure p is used for comparison. sortff(L, fields[]) like sortf(), except takes an unlimited number of field arguments. sortgen(T, m) generates sorted output in a manner specified by m: "k+" sort by key in ascending order "k-" sort by key in descending order "v+" sort by value in ascending order "v-" sort by value in descending order sortt(T, i) like sort(T, i) but produces a list of two-element records instead of a list of two-element lists. ____________________________________________________________ Customizable sort procedure for inclusion in Icon programs. isort(x,keyproc,y) Argument x can be any Icon data type that is divisible into elements by the unary element generation (!) operator. The result is a list of the objects in sorted order. The default is to sort elements in their natural, Icon-defined order. However, an optional parameter (keyproc) allows a sort key to be derived from each element, rather than the default of using the element itself as the key. Keyproc can be a procedure provided by the caller, in which case the first argument to the key procedure is the item for which the key is to be computed, and the second argument is isort's argument y, passed unchanged. The keyproc must produce the extracted key. Alternatively, the keyproc argument can be an integer, in which case it specifies a subscript to be applied to each item to produce a key. Keyproc will be called once for each element of structure x.