--  Singly linked lists of integers, owned through access values and freed explicitly.
package Lists is
   type Node;
   type List is access Node;
   type Node is record
      Value : Integer := 0;
      Next  : List;
   end record;

   procedure Push (L : in out List; V : Integer)
     with Post => L /= null and then L.Value = V;

   --  the first value of a list, or a default for an empty one
   function Head_Or (L : List; Default : Integer) return Integer is
     (if L = null then Default else L.Value);

   procedure Append (L : in out List; V : Integer)
     with Post => L /= null and Head_Or (L, 0) = Head_Or (L, V)'Old;

   procedure Reverse_List (L : in out List);

   procedure Length (L : List; N : out Natural);

   procedure Print (L : List);

   procedure Halve_All (L : in out List);

   procedure Clear (L : in out List)
     with Post => L = null;
end Lists;
