SortedBy -- sort a list |
Syntax |
SortedBy(L: LIST, LessThanFn: FUNCTION): LIST |
Description |
Example |
/**/ Define LessByLength(S, T) -- define the sorting function /**/ Return len(S) < len(T); /**/ EndDefine; /**/ L := ["bird","mouse","cat", "elephant"]; /**/ sorted(L); -- default is alphabetical order ["bird", "cat", "elephant", "mouse"] /**/ SortedBy(L, LessByLength); ["cat", "bird", "mouse", "elephant"] /**/ L; -- L is not changed ["bird", "mouse", "cat", "elephant"] /**/ SortBy(ref L, LessByLength); -- sort L in place, changing L /**/ L; ["cat", "bird", "mouse", "elephant"] |
See Also |