:: Re: [DNG] another programming langu…
Kezdőlap
Delete this message
Reply to this message
Szerző: Steve Litt
Dátum:  
Címzett: dng
Tárgy: Re: [DNG] another programming language question
Didier Kryn said on Fri, 25 Oct 2024 13:39:37 +0200

>     In a program or subprogram body in Ada, you ave three sections
>separated by the following lines:
>
>declare,
>
>begin,
>
>exception.


>     The last section, which is optionnal, is where you decide what to
>do with exceptions, either cure the problem, print some smart
>information, convert it to another exception and forward it to the
>caller, or what else.


The declare word is optional too. The lines between "procedure whatever
is" and the first "begin" are automatically declaration material. You
use the word "declare" when you want to make declarations in the
middle, like the following:

========================================================

with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;

procedure Declare_Example is
   Array_Size: Integer;
begin
   Put("Type in array size please: ");
   Array_Size := Integer'Value(Get_Line);
   New_Line;
   declare
      type Array_Type is
         array(1..Array_Size) of Integer;
   begin
      Put("Size of array is ");
      Put(Array_Type'last);
      Put_Line(" Elements.");
   end;
   Put_Line("Thanks!");
end Declare_Example;


========================================================

You needed to run code before declaring type Array_Type, and for that
reason alone, needed an explicit declare block with its declaration
area, begin, execution area, and end. The reason you needed to declare
the type in the middle was because the new type's size depended on
executable code.

But in general if you keep all your declarations between the procedure
or function statement and the first "begin" after that, you have no
need for the declare verb.

SteveT

Steve Litt

http://444domains.com