Paulo brought in a predicate definition group/2, answering a question on stackoverflow, that I think should replace transpose/2 in library(clpfd).
Some dummy raw performance test:
?- N=1000,length(M,N),maplist({N}/[R]>>length(R,N),M),time(transpose(M,T)).
% 3,007,008 inferences, 1.170 CPU in 1.170 seconds (100% CPU, 2571118 Lips)
?- N=1000,length(M,N),maplist({N}/[R]>>length(R,N),M),time(group(M,T)).
% 1,003,002 inferences, 0.341 CPU in 0.341 seconds (100% CPU, 2938693 Lips)
And it’s almost reversible
?- group(X,[[1,2,3],[4,5,6]]).
X = [[1, 4], [2, 5|_2262], [3, 6|_2274]].
Would be nice to get rid of the last unbound element… but not essential, since currently transpose/2 needs a list of lists as first argument anyway.
If someone else thinks it could be useful, I’ll attempt to issue a proper PR for library(clpfd).