10-28-2018, 11:46 PM
I have just added a list transpose implementation to my List API
But I was expecting the built-in sequence mat2list(transpose(list2mat)) to give the same results.
It is similar, but flatter than my implementation.
Am I wrong?
Code:
//TRY WITH ({{1,2,3},{4,5,6}})
EXPORT ListTRANSPOSE(LST)
//LIST TRANSPOSE
//WITH A 2D LST TRN(TRN(LST)) RETURNS ORIGINAL LIST
//A 1D LIST HAS NO PROPER TRANSPOSE AND MIGHT NOT RETURN USEFUL LST
//NOTE This is similar to the obvious builtin
//PRINT(mat2list(transpose(list2mat({{1,2,3},{4,5,6}}))));
//But the builtin unexpectedly flattens too
BEGIN
LOCAL II,JJ;
LOCAL OUT:={};
FOR II FROM 1 TO SIZE(LST) DO
IF TYPE(LST(II))==TYPE({}) THEN //2D
FOR JJ FROM 1 TO SIZE(LST(II)) DO
OUT(JJ,II):=LST(II,JJ);
END;//FOR
ELSE
//GUARD FLAT LIST//WHATS GOOD HERE? AN ERR MAY BE BETTER
//NEITHER OF THESE ARE IDEAL IN ALL CASES
OUT(II):=LST(II);
//OUT(II):={LST(II)};
END;//IF
END;//FOR
PRINT(mat2list(transpose(list2mat(LST)))); //why are these different?
PRINT(OUT); //and which is correct?
RETURN OUT;
END;
It is similar, but flatter than my implementation.
Am I wrong?