Bonjour,

Pour les besoins d'un programme prolog, je dois transposer une matrice, Par exemple je souhaite transformer:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
[[1,2,3],
 [4,5,6],
 [7,8,9]]
en
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
[[1,4,7],
 [2,5,8],
 [3,6,9]]
J'ai donc écrit ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
tlil([],_).
tlil([X|Y],Transp):-
	tlil2(X,Transp,NewTransp),
	tlil(Y,NewTransp),
	Transp is NewTransp.
 
tlil2([],[],[]).
tlil2([A|B],[],X):-
	tlil2(B,[],X2),
	append([[A]],X2,X).
tlil2([A|B],[C|D],X):-
	append([A],C,X1),
	tlil2(B,D,X2),
	append([X1],X2,X).
Je vois pas trop quels commentaires ajouter, alors j'espère que le code vous semble compréhensible.

J'appelle donc:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
tlil([[1,2,3],[4,5,6],[7,8,9]],X).
et je m'attends à obtenir :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
X = [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
Au lieu de ça, j'ai juste un:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
ERROR: Type error: `character' expected, found `[3, 1]'
Un petit coup de:
me donne :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
   Call: (7) tlil([[1, 2], [3, 4]], _G490) ? creep
   Call: (8) tlil2([1, 2], _G490, _G563) ? creep
   Call: (9) tlil2([2], [], _G563) ? creep
   Call: (10) tlil2([], [], _G563) ? creep
   Exit: (10) tlil2([], [], []) ? creep
   Call: (10) append([[2]], [], _G572) ? creep
   Exit: (10) append([[2]], [], [[2]]) ? creep
   Exit: (9) tlil2([2], [], [[2]]) ? creep
   Call: (9) append([[1]], [[2]], _G581) ? creep
   Exit: (9) append([[1]], [[2]], [[1], [2]]) ? creep
   Exit: (8) tlil2([1, 2], [], [[1], [2]]) ? creep
   Call: (8) tlil([[3, 4]], [[1], [2]]) ? creep
   Call: (9) tlil2([3, 4], [[1], [2]], _G581) ? creep
   Call: (10) append([3], [1], _G587) ? creep
   Exit: (10) append([3], [1], [3, 1]) ? creep
   Call: (10) tlil2([4], [[2]], _G587) ? creep
   Call: (11) append([4], [2], _G593) ? creep
   Exit: (11) append([4], [2], [4, 2]) ? creep
   Call: (11) tlil2([], [], _G593) ? creep
   Exit: (11) tlil2([], [], []) ? creep
   Call: (11) append([[4, 2]], [], _G599) ? creep
   Exit: (11) append([[4, 2]], [], [[4, 2]]) ? creep
   Exit: (10) tlil2([4], [[2]], [[4, 2]]) ? creep
   Call: (10) append([[3, 1]], [[4, 2]], _G605) ? creep
   Exit: (10) append([[3, 1]], [[4, 2]], [[3, 1], [4, 2]]) ? creep
   Exit: (9) tlil2([3, 4], [[1], [2]], [[3, 1], [4, 2]]) ? creep
   Call: (9) tlil([], [[3, 1], [4, 2]]) ? creep
   Exit: (9) tlil([], [[3, 1], [4, 2]]) ? creep
^  Call: (9) [[1], [2]]is[[3, 1], [4, 2]] ? creep
ERROR: Type error: `character' expected, found `[3, 1]'
^  Exception: (9) [[1], [2]]is[[3, 1], [4, 2]] ? creep
   Exception: (8) tlil([[3, 4]], [[1], [2]]) ? creep
   Exception: (7) tlil([[1, 2], [3, 4]], _G490) ? creep
Je ne comprends pas... Ça devrait marcher, bor*** de m**** !!! Non?

Merci d'avance pour votre bonne volonté...[/i]