Define ByLength(S, T) -- define the sorting function
Return Len(S) > Len(T);
EndDefine;
M := ["dog","mouse","cat"];
SortedBy(M, Function("ByLength"));
["mouse", "dog", "cat"]
-------------------------------
M; -- M is not changed
["dog", "mouse", "cat"]
-------------------------------
Sorted(M); -- the function "Sort" sorts using the default ordering:
-- in this case, alphabetical order.
["cat", "dog", "mouse"]
-------------------------------
SortBy(M, Function("ByLength")); -- sort M in place, changing M
M;
["mouse", "dog", "cat"]
-------------------------------
|