--  An element of an enclave's list changed in place (F4, E4): Update_Element applies a
--  procedure to the element in its cell, and the model says what it became

with Ada.Text_IO;
with Verada.Containers.Linked_Lists;

procedure Main is
   package Lists is new Verada.Containers.Linked_Lists (Integer);
   use type Lists.Element_Sequences.Sequence;

   function Doubled (E : Integer) return Integer is (if E in -1000 .. 1000 then 2 * E else E) with Ghost;
   procedure Double (E : in out Integer) with Global => null, Post => E = Doubled (E'Old) is
   begin
      if E in -1000 .. 1000 then
         E := 2 * E;
      end if;
   end Double;
   procedure Double_At is new Lists.Update_Element (Doubled, Double);

   L : Lists.List;
begin
   Lists.Append (L, 1);
   Lists.Append (L, 2);
   Lists.Append (L, 3);
   Double_At (L, 2);
   pragma Assert (Lists.Element_Sequences.Get (Lists.Model (L), 2) = 4);
   pragma Assert (Lists.Element_Sequences.Get (Lists.Model (L), 3) = 3);
   Ada.Text_IO.Put_Line (Integer'Image (Lists.First_Element (L)) & Integer'Image (Lists.Last_Element (L)) & Integer'Image (Lists.Length (L)));
end Main;
