>I have been trying to make a procudure to sort a list of lists into
>ascending numberical value. For example, if the list of lists is [[0 1]
>[1 1] [0 3] [4 0]] I would like the outcome to be [[4 0] [0 3] [1 1] [0
>1]] or [[0 1] [1 1] [0 3] [4 0]] - it doesn't matter.
If this means "sort a list of lists by the sum of the numbers in each
sublist", you could do:
define sum(list);
if list == [] then 0 else applist(dest(list), nonop +) endif
enddefine;
define sort_by_sublist_sum(list);
syssort(list, procedure(l1, l2); sum(l1) >= sum(l2) endprocedure)
enddefine;
e.g.
sort_by_sublist_sum([[0 1] [1 1] [0 3] [4 0]]) =>
** [[4 0] [0 3] [1 1] [0 1]]
See HELP SYSSORT.
John.
|