DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Generic package Verada.Containers.Functional.Sequences

Verada predefined library: functional sequences, the unbounded ghost models that container contracts are written against. A Sequence is a value: Add and Set make a new one. The package is ghost; Verada's prover sees a Sequence as its own sequences (the arrays with run-time bounds), the interpreter as such an array, and no code is generated for it.

generic
   type Element_Type is private;

Sequence

type Sequence is private;

Empty_Sequence

function Empty_Sequence return Sequence
  with Global => null,
       Post => Length (Empty_Sequence'Result) = 0;

the empty sequence

Length

function Length (Container : Sequence) return Natural
  with Global => null;

Get

function Get (Container : Sequence; Position : Positive) return Element_Type
  with Global => null,
       Pre => Position <= Length (Container);

the element at a position, from 1

Last

function Last (Container : Sequence) return Natural is (Length (Container));

Add

function Add (Container : Sequence; New_Item : Element_Type) return Sequence
  with Global => null,
       Pre => Length (Container) < Natural'Last,
       Post => Length (Add'Result) = Length (Container) + 1
               and then Get (Add'Result, Length (Add'Result)) = New_Item
               and then (for all I in 1 .. Length (Container) => Get (Add'Result, I) = Get (Container, I));

Container with New_Item at its end

Set

function Set (Container : Sequence; Position : Positive; New_Item : Element_Type) return Sequence
  with Global => null,
       Pre => Position <= Length (Container),
       Post => Length (Set'Result) = Length (Container)
               and then Get (Set'Result, Position) = New_Item
               and then (for all I in 1 .. Length (Container) => (if I /= Position then Get (Set'Result, I) = Get (Container, I)));

Container with New_Item at Position

Prepend

function Prepend (Container : Sequence; New_Item : Element_Type) return Sequence
  with Global => null,
       Pre => Length (Container) < Natural'Last,
       Post => Length (Prepend'Result) = Length (Container) + 1
               and then Get (Prepend'Result, 1) = New_Item
               and then (for all I in 1 .. Length (Container) => Get (Prepend'Result, I + 1) = Get (Container, I));

Container with New_Item at its start

Remove_First

function Remove_First (Container : Sequence) return Sequence
  with Global => null,
       Pre => Length (Container) > 0,
       Post => Length (Remove_First'Result) = Length (Container) - 1
               and then (for all I in 1 .. Length (Remove_First'Result) => Get (Remove_First'Result, I) = Get (Container, I + 1));

Container without its first element

Remove_Last

function Remove_Last (Container : Sequence) return Sequence
  with Global => null,
       Pre => Length (Container) > 0,
       Post => Length (Remove_Last'Result) = Length (Container) - 1
               and then (for all I in 1 .. Length (Remove_Last'Result) => Get (Remove_Last'Result, I) = Get (Container, I));

Container without its last element

function "=" (Left, Right : Sequence) return Boolean
  with Global => null,
       Post => "="'Result = (Length (Left) = Length (Right)
                             and then (for all I in 1 .. Length (Left) => Get (Left, I) = Get (Right, I)));

the same elements in the same order

function "<=" (Left, Right : Sequence) return Boolean
  with Global => null,
       Post => "<="'Result = (Length (Left) <= Length (Right)
                              and then (for all I in 1 .. Length (Left) => Get (Left, I) = Get (Right, I)));

Left is a prefix of Right

Contains

function Contains (Container : Sequence; Item : Element_Type) return Boolean is
  (for some I in 1 .. Length (Container) => Get (Container, I) = Item);

Equal_Elements

function Equal_Elements (Left, Right : Element_Type) return Boolean is (Left = Right);

Left and Right are the same value: the element type's own equality, which a container whose "=" for elements is a generic formal (Ada.Containers') states its contracts with