Software Engineers Handbook/Language Dictionary/Ada
Ada
[edit | edit source]Ada is a strongly typed Multi-paradigmed programming language suitable for embedded systems, device drivers and other forms of system programming.
Type
[edit | edit source]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 | edit source]The procedure name of the entry point can be freely choosen.
General Syntax
[edit | edit source]The typical statement is completed by a semi-colon. For the assignment of b to a use:
a := b ;
Comments
[edit | edit source]-- this is an inline comment. Everything after the -- is a comment.
Variable Declarations
[edit | edit source]Declarations can appear at the beginning of an block.
Declare i as an integer:
declare
I : Integer ;begin
-- programend
;
Here are two ways to declare i as an integer and give it an initial value of 0:
declare
I : Integer := 0 ;begin
-- programend
;
Method Declaration/Implementation
[edit | edit source]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
Integeris
begin
if
A <= Bthen
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 | edit source]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_Bodyis
type
Basic_Recordis
private
;procedure
Set_A (This :in
out
Basic_Record; An_A :in
Integer);function
Get_A (This : Basic_Record)return
Integer;private
type
Basic_Recordis
record
A : Integer;end
record
;end
Package_With_Body;
package
body
Package_With_Bodyis
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
Integeris
begin
return
This.A;end
Get_A;end
Package_With_Body;
See Ada_Programming/Packages for details.
Conditional Statements
[edit | edit source]<Describe the conditional statements in text and present
if
A < Range_Type'Lastthen
T_IO.Put (",");else
T_IO.New_Line;end
if
;
See Ada_Programming/Control#if-else for details.
Looping Statements
[edit | edit source]<Describe looping statements in English and present code examples.>
for
Ain
Range_Typeloop
I_IO.Put (Item => A, Width => 3, Base => 10);if
A < Range_Type'Lastthen
T_IO.Put (",");else
T_IO.New_Line;end
if
;end
loop
;
See Ada Programming/Control#loops for details.
Output Statements
[edit | edit source]<Describe how to output Hello world! including the new-line with or without a carriage return.>
with
Ada.Text_IO;procedure
Hellois
begin
Ada.Text_IO.Put_Line("Hello, world!");end
Hello;
See Ada_Programming/Libraries/Ada.Text_IO for details.
Error Handling/Recovery
[edit | edit source]<Describe error handling and recovery. Give examples as appropriate.>
See Ada_Programming/Exceptions for details.
Containers
[edit | edit source]The following predefined packages are now available natively within Ada (since Ada 2005):
- Ada.Containers.Doubly_Linked_Lists
- Ada.Containers.Hashed_Maps
- Ada.Containers.Hashed_Sets
- Ada.Containers.Ordered_Maps
- Ada.Containers.Ordered_Sets
- Ada.Containers.Vectors
These are definite versions - indefinite versions of each area also provided. All containers are unbounded.
Algorithms
[edit | edit source]<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 | edit source]Carbage collections can be either manual or automatic - refer to your compiler handbook. If automatic collection is provided then
can deactivate atomatic collection for the named access type.
pragma
Controlled ()
For manual deallocation the package Ada.Unchecked_Deallocation is used.
See Ada Programming/Types/access for details.
Physical Structure
[edit | edit source]<Describe how the files, libararies, and parts are typically divided and arranged.>
Tips
[edit | edit source]<Please include tips that make it easier to switch to this language from another language.>
Web References
[edit | edit source]- Ada Programming - - (Index) (this wikibook is a tutorial)