I'm very new to GAP, and I'm struggling with SortBy. Starting with a list of lists, I want to sort each list by AbsoluteValue in GAP. However, I can only get Sort or SortBy to work outside of a loop. The problem exists already in this tiny example:
gap> A:=[[-5,-3,-1,2,4,6],[-6,-4,-2,1,3,5]];
[ [ -5, -3, -1, 2, 4, 6 ], [ -6, -4, -2, 1, 3, 5 ] ]
gap> sorter:=function(X)
> for i in [1..Length(X)] do
> X[i]:=SortBy(X[i],AbsoluteValue);
> od;
> end;;
gap> sorter(A);
Error, Function Calls: <func> must return a value in
X[i] := SortBy( X[i], AbsoluteValue ); at *stdin*:24 called from
<function "sorter">( <arguments> )
called from read-eval loop at line 27 of *stdin*
you can supply one by 'return <value>;'
brk>
gap> A[1];A[2];
[ -1, 2, -3, 4, -5, 6 ]
[ -6, -4, -2, 1, 3, 5 ]
It sorts the first list, but apparently doesn't like the second one. I think the error message says that AbsoluteValue doesn't return a value, which is false. What am I missing?
SortBy
that does not return anything. Enter?SortBy
in GAP to see its documentation and examples. $\endgroup$