g***@gmail.com
2017-11-28 21:57:28 UTC
Première tentative à coder quelque chose de conséquence, je veux dire plus que des procédures pour lire et écrire des chaînes ou des entiers bornés. J'essaie d'apprendre par moi-même, avec les cours qu'on trouve sur le net (je suis en licence d'histoire deuxième année dans la vraie vie), en faisant et compilant les exos. Pas de professeurs, pas de correction. Si ça ne dérange pas, je vous demanderai de l'aide quand je ne comprendrai pas les messages du compilateur ou voudrai des éclaircissements sur les rêgles.
Ici, la compilation échoue. Pour les spécifications:
$ gcc-6 -c tri_selection.ads
cannot generate code for file tri_selection.ads (package spec)
gnatmake: "tri_selection.ads" compilation error
je pensais que les spécifications pouvaient se compiler à part ?
generic
type Element_type is (<>);
type Indice_type is (<>);
type Tableau_type is array (Indice_type range <>) of Element_type;
package Tri_selection is
procedure tri (T: in out Tableau_type);
end Tri_selection;
Quant au corps, voilà le message:
***@debian:~/essai$ gnatmake tri_selection.adb
gcc-6 -c tri_selection.adb
tri_selection.adb:7:35: expected type "Indice_type" defined at tri_selection.ads:3
tri_selection.adb:7:35: found type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:8:27: expected type "Indice_type" defined at tri_selection.ads:3
tri_selection.adb:8:27: found type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:8:35: expected type "Indice_type" defined at tri_selection.ads:3
tri_selection.adb:8:35: found type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:9:27: expected type "Indice_type" defined at tri_selection.ads:3
tri_selection.adb:9:27: found type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:9:35: expected type "Indice_type" defined at tri_selection.ads:3
tri_selection.adb:9:35: found type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:19:33: expected type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:19:33: found type "Indice_type" defined at tri_selection.ads:3
gnatmake: "tri_selection.adb" compilation error
voilà le code si jamais. J'ai corrigé les fautes de syntaxe bête (virgules au lieu de point-virgule, rien de plus), mais il reste les message plus haut.
package body Tri_selection is
temp : Element_type;
procedure tri (T: in out Tableau_type) is
procedure Swap (T: in out Tableau_type; A, B : in out Element_type) is
temp: Element_type;
begin
temp := T(A);
T(A) := T(B);
T(B) := T(A);
end Swap;
temp: Indice_type;
begin
for I in Tableau_type'Range loop
for J in I..Tableau_type'Last loop
if T(J) < T(Tableau_type'Last) then temp := J;
end if;
end loop;
Swap (T,temp,Tableau_type'Last);
end loop;
end tri;
end Tri_selection;
Ici, la compilation échoue. Pour les spécifications:
$ gcc-6 -c tri_selection.ads
cannot generate code for file tri_selection.ads (package spec)
gnatmake: "tri_selection.ads" compilation error
je pensais que les spécifications pouvaient se compiler à part ?
generic
type Element_type is (<>);
type Indice_type is (<>);
type Tableau_type is array (Indice_type range <>) of Element_type;
package Tri_selection is
procedure tri (T: in out Tableau_type);
end Tri_selection;
Quant au corps, voilà le message:
***@debian:~/essai$ gnatmake tri_selection.adb
gcc-6 -c tri_selection.adb
tri_selection.adb:7:35: expected type "Indice_type" defined at tri_selection.ads:3
tri_selection.adb:7:35: found type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:8:27: expected type "Indice_type" defined at tri_selection.ads:3
tri_selection.adb:8:27: found type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:8:35: expected type "Indice_type" defined at tri_selection.ads:3
tri_selection.adb:8:35: found type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:9:27: expected type "Indice_type" defined at tri_selection.ads:3
tri_selection.adb:9:27: found type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:9:35: expected type "Indice_type" defined at tri_selection.ads:3
tri_selection.adb:9:35: found type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:19:33: expected type "Element_type" defined at tri_selection.ads:2
tri_selection.adb:19:33: found type "Indice_type" defined at tri_selection.ads:3
gnatmake: "tri_selection.adb" compilation error
voilà le code si jamais. J'ai corrigé les fautes de syntaxe bête (virgules au lieu de point-virgule, rien de plus), mais il reste les message plus haut.
package body Tri_selection is
temp : Element_type;
procedure tri (T: in out Tableau_type) is
procedure Swap (T: in out Tableau_type; A, B : in out Element_type) is
temp: Element_type;
begin
temp := T(A);
T(A) := T(B);
T(B) := T(A);
end Swap;
temp: Indice_type;
begin
for I in Tableau_type'Range loop
for J in I..Tableau_type'Last loop
if T(J) < T(Tableau_type'Last) then temp := J;
end if;
end loop;
Swap (T,temp,Tableau_type'Last);
end loop;
end tri;
end Tri_selection;