Software Engineers Handbook/Language Dictionary/Ada

Ada is a strongly typed Multi-paradigmed programming language suitable for embedded systems, device drivers and other forms of system programming.

Type

edit

Ada is a full Multi-paradigmed programming language implementing the following paradigmen: concurrent, distributed, generic (template metaprogramming), imperative and object-oriented (class-based) programming.

Execution Entry Point

edit

The procedure name of the entry point can be freely choosen.

General Syntax

edit

The typical statement is completed by a semi-colon. For the assignment of b to a use:

a := b ;

Comments

edit
-- this is an inline comment.  Everything after the -- is a comment.

Variable Declarations

edit

Declarations can appear at the beginning of an block.

Declare i as an integer:

declare 
  I : Integer ; 
begin
  -- program
end ; 

Here are two ways to declare i as an integer and give it an initial value of 0:

declare 
  I : Integer := 0 ; 
begin
  -- program
end ;

Method Declaration/Implementation

edit

procedures and functions are declared by the keyword procedure or function respectively. See Ada Programming/Subprograms for details.

procedure A_Test (A, B: in Integer; C: out Integer) is
begin
   C := A + B;
end A_Test;
function Minimum (A, B : Integer) return Integer is
begin
   if A <= B then
      return B;
   else
      return A;
   end if;
end Minimum;

Class methods are primitive operations (procedures and functions) declared in the same scope as the class record. See Ada_Programming/Object_Orientation for details.

Scope

edit

Scope is declared by the use of packages which may consist of three parts: public specification (package), private specification (private) and body (package body).

package Package_With_Body is

   type Basic_Record is private;

   procedure Set_A (This : in out Basic_Record;
                    An_A : in     Integer);

   function Get_A (This : Basic_Record) return Integer;

private

   type Basic_Record is 
      record 
         A : Integer;
      end record ;

end Package_With_Body;
package body Package_With_Body is

   procedure Set_A (This : in out Basic_Record;
                    An_A : in     Integer)
   is
   begin
      This.A := An_A;
   end Set_A;

   function Get_A (This : Basic_Record) return Integer is
   begin
      return This.A;
   end Get_A;

end Package_With_Body;

See Ada_Programming/Packages for details.

Conditional Statements

edit

<Describe the conditional statements in text and present

File: range_1.adb (view, plain text, download page, browse all)
      if A < Range_Type'Last then
         T_IO.Put (",");
      else
         T_IO.New_Line;
      end if;

See Ada_Programming/Control#if-else for details.

Looping Statements

edit

<Describe looping statements in English and present code examples.>

File: range_1.adb (view, plain text, download page, browse all)
   for A in Range_Type loop
      I_IO.Put (Item  => A,
                Width => 3,
                Base  => 10);

      if A < Range_Type'Last then
         T_IO.Put (",");
      else
         T_IO.New_Line;
      end if;
   end loop;

See Ada Programming/Control#loops for details.

Output Statements

edit

<Describe how to output Hello world! including the new-line with or without a carriage return.>

File: hello_world_1.adb (view, plain text, download page, browse all)
with Ada.Text_IO;

procedure Hello is
begin
   Ada.Text_IO.Put_Line("Hello, world!");
end Hello;

See Ada_Programming/Libraries/Ada.Text_IO for details.

Error Handling/Recovery

edit

<Describe error handling and recovery. Give examples as appropriate.>

See Ada_Programming/Exceptions for details.

Containers

edit

The following predefined packages are now available natively within Ada (since Ada 2005):

These are definite versions - indefinite versions of each area also provided. All containers are unbounded.

Algorithms

edit

<List algorithms or references to lists of algorithms available natively for this language. List ways to incorporate algorithms if they are not native to the language. Or, if not available, describe that.>

Garbage collection

edit

Carbage collections can be either manual or automatic - refer to your compiler handbook. If automatic collection is provided then pragma Controlled () can deactivate atomatic collection for the named access type.

For manual deallocation the package Ada.Unchecked_Deallocation is used.

See Ada Programming/Types/access for details.

Physical Structure

edit

<Describe how the files, libararies, and parts are typically divided and arranged.>

Tips

edit

<Please include tips that make it easier to switch to this language from another language.>

Web References

edit

Books and Articles

edit