Ada Conformity Assessment Authority      Home Conformity Assessment   Test Suite ARGAda Standard
Overview of Ada 2022
Jeff Cousins
Contents   Index   Search   Previous   Next 

3.6 Declare expressions

Declare expressions (AI12-0236) (see RM 4.5.9). As the power of expressions has grown, some felt that it would help to allow local constants and object renamings within an expression, to avoid repeated subexpressions. For example, the postcondition for Fgetc could be clarified from: 
(if Stream.The_File (Stream.Cur_Position'Old) =
 then Stream.Cur_Position = Stream.Cur_Position'Old
    and then Result = EOF
 elsif Stream.The_File (Stream.Cur_Position'Old) =
 then Stream.Cur_Position = Stream.Cur_Position'Old
    and then Result = Character'Pos (ASCII.LF)
    Stream.Cur_Position = Stream.Cur_Position'Old + 1
    and then Result = Character'Pos (Stream.The_File
   Old_Pos : constant Position :=
   The_Char : constant Character :=
   Pos_Unchg : constant Boolean :=
                Stream.Cur_Position = Old_Pos;
   (if The_Char = EOF_Ch
      then Pos_Unchg and then Result = EOF
    elsif The_Char = ASCII.LF
      then Pos_Unchg and then Result = 
      Stream.Cur_Position = Old_Pos + 1
      and then Result = Character'Pos (The_Char)))
This uses the reserved words declare and begin, as for a block, but not end, as it is only used within parentheses. Declare expressions can be static (AI12-0368) allows these new declare expressions to be static.

Contents   Index   Search   Previous   Next 
© 2021, 2022 Jeff Cousins