Anonymous user
Matrix transposition: Difference between revisions
→{{header|Prolog}}
Line 1,104:
enddefine;</lang>
=={{header|Prolog}}==
In Prolog, a matrix is a list of lists. transpose/2 can be written like that. <BR>
Works with SWI-Prolog.
<lang Prolog>% transposition of a rectangular matrix
Line 1,118 ⟶ 1,120:
initdl(V, [V | X] - X).
work(Lst, [H], Out) :-
work(Lst, [H | T], Out) :-
Line 1,127 ⟶ 1,129:
my_append(X-Y, C, X1-Y1) :-
append_dl(X-Y, [C | U]- U, X1-Y1).
my_append_last(X-Y, C, X1) :-
append_dl(X-Y, [C | U]- U, X1-[]).
% "quick" append
append_dl(X-Y, Y-Z, X-Z).
</lang>
|