Hi;
I’m trying to compile (then understand!) a pre-existing Rosetta Code task written in Ada. I didn’t submit this task.
The task, as submitted, has three parts. It looks as though there are two procedures which should be inserted as local procedures inside the main routine.
I’ve done that (see below) and tried to compile (see results below).
What am I doing wrong?
It looks to me that the submitter of the code is not specifying the functions/procedures defined in the Ada.Containers.Doubly_Linked_Lists package, only using a with clause. That’s my best guess. But it looks like there is more than that which is causing the compile failure.
The code (spliced by me, perhaps incorrectly):
-- Element insertion using the generic doubly linked list defined in
-- the standard Ada containers library.
with Ada.Containers.Doubly_Linked_Lists;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
procedure List_Insertion is
package String_List is new Ada.Containers.Doubly_Linked_Lists
(Unbounded_String);
use String_List;
procedure Make_List is
A, B, C : Link_Access;
begin
A := new Link;
B := new Link;
C := new Link;
A.Data := 1;
B.Data := 2;
C.Data := 2;
Insert (Anchor => A, New_Link => B); -- The list is (A, B)
Insert (Anchor => A, New_Link => C); -- The list is (A, C, B)
end Make_List;
procedure Insert (Anchor : Link_Access; New_Link : Link_Access) is
begin
if Anchor /= null and New_Link /= null then
New_Link.Next := Anchor.Next;
New_Link.Prev := Anchor;
if New_Link.Next /= null then
New_Link.Next.Prev := New_Link;
end if;
Anchor.Next := New_Link;
end if;
end Insert;
procedure Print (Position : Cursor) is
begin
Put_Line (To_String (Element (Position)));
end Print;
The_List : List;
begin
The_List.Append (To_Unbounded_String ("A"));
The_List.Append (To_Unbounded_String ("B"));
The_List.Insert
(Before => The_List.Find (To_Unbounded_String ("B")),
New_Item => To_Unbounded_String ("C"));
The_List.Iterate (Print'Access);
end List_Insertion;
gnatmake output:
gnatmake ./list_insertion.adb
gcc -c -I./ -I- ./list_insertion.adb
list_insertion.adb:13:31: error: "Link_Access" is undefined (more references follow)
list_insertion.adb:16:10: error: invalid prefix in selected component "New_Link"
list_insertion.adb:16:27: error: invalid prefix in selected component "Anchor"
list_insertion.adb:17:10: error: invalid prefix in selected component "New_Link"
list_insertion.adb:18:13: error: invalid prefix in selected component "New_Link"
list_insertion.adb:19:13: error: invalid prefix in selected component "New_Link"
list_insertion.adb:21:10: error: invalid prefix in selected component "Anchor"
list_insertion.adb:28:21: error: "Link" is undefined (more references follow)
list_insertion.adb:28:21: error: possible misspelling of "Line"
list_insertion.adb:31:07: error: invalid prefix in selected component "A"
list_insertion.adb:32:07: error: invalid prefix in selected component "B"
list_insertion.adb:33:07: error: invalid prefix in selected component "C"
gnatmake: "./list_insertion.adb" compilation error
platform: MacOS M1
gnat version:
gnatmake --version
GNATMAKE 15.0.1 20250418 (prerelease)
Thanks in advance,
RBE