with Ada.Text_IO; use Ada.Text_IO; procedure List is type MyList; type MyList_Access is access MyList; type MyList is record Value : Integer := 0; Next : MyList_Access := null; end record; function Length (XS : access constant MyList) return Integer is L : Integer := 0; Node : access constant MyList := XS; begin while Node /= null loop L := L + 1; Node := Node.Next; end loop; return L; end Length; procedure Print_List (XS : access constant MyList) is begin if XS /= null then Put (Integer'Image (XS.Value) & " "); Print_List (XS.Next); end if; end Print_List; function Build_List return MyList_Access is XS : MyList_Access := new MyList'(1, new MyList'(2, new MyList'(3, null))); begin return XS; end Build_List; XS : MyList_Access := Build_List; begin Put ("List: "); Print_List (XS); New_Line; Put_Line ("The list has length " & Integer'Image (Length (XS))); end List;