Why is transpose/2 not in library(lists)?

Is there a particular reason why transpose/2 is in library(clpfd) and not in library(lists)?

There are arguments why it belongs there (works on lists) and it would also become autoloaded.

One concern is the maplist and foldl in the current implementation, that probably slow it down a tiny bit.

The copyright notice should be copied as well.

Opinions?

Seems (see this thread) that the culprit for lost performance could be the same_length/2 check instead of foldl. Anyway, I found Paulo’ alternative implementation compelling, and would welcome a move of the much needed functionality of transpose/2 to library(lists), where it belongs… except for backlog compatibility…

Without the samel_length/2 check, the code is:


transpose([], []).
transpose([L|Ls], Ts) :-
    foldl(transpose_, L, Ts, [L|Ls], _).

transpose_(_, Fs, Lists0, Lists) :-
    maplist(list_first_rest, Lists0, Fs, Lists).

list_first_rest([X|Xs], X, Xs).

Here’s an alternative implementation, for those who want to benchmark:

transpose([], []).
transpose([X|Xs], Ys) :-
    transpose(X, [X|Xs], Ys).

transpose([], _, []).
transpose([_|_], X, [MapHeadX|TransposeMapTailX]) :-
    maplist(list_first_rest, X, MapHeadX, MapTailX),
    transpose(MapTailX, TransposeMapTailX).

list_first_rest([X|Xs], X, Xs).

And don’t forget to use library(apply_macros) to get faster versions of maplist, foldl, etc.