Ada is a computer programming
language originally designed to support the construction of long-lived, highly
reliable software systems. Its design emphasizes readability, avoids error-prone
notation, encourages reuse and team coordination, and it is designed to be
efficiently implementable.
The first programmer Lady Lovelace
programmed in the Ada Programming Language around 1850. She was born in 1815 and
die in 1852. She worked with Charles Babbage, who had created a “difference
engine” that could be programmed much like a Jacquard loom. The language’s name
Ada was chosen after because Ada(Lady Lovelace) often “programmed” the
difference engine.
After
more than hundred years, Ada Language came to the attention of the Computer
Science Community. In 1974, many groups began to study specially the army
started to implement Ada. The army called it, Language for Real Time Systems;
the navy called CS4 Program; the Air Force effort was named the High Order
Language Standardization Study.
The overall result of those army
projects led to the first military standard specification
MIL-STD-1815.
And in 1983 Ada/Ed was
standardized to ANSI document.
Ada 95 was designed and developed from an international process of
unprecedented scale for a programming language. This revision retains the
original version of Ada 83. Ada 95 provides support for object oriented
programming.
Here's a simple program in Ada
that simply prints a message, often called the hello, world! program
(for the moment, ignore the buttons below the sample program):
Here's an explanation of each line:
Ada terminates each statement with a semicolon.
This is like C and C++ and unlike standard Pascal (which uses semicolons as
statement separators).
Let's create a program to show
what a simple variable and parameter-passing look like. This program will print
out powers of 2, starting with 1, ``forever''. We'll call this program procedure
Compute.
Inside this procedure create a local procedure
called Double which doubles any number given to it, and a local integer variable
named `X'.
Demonstrate a trivial procedure,
with another nested inside.
with Ada.Text_IO,
Ada.Integer_Text_IO;
use Ada.Text_IO,
Ada.Integer_Text_IO;
procedure Compute
is
procedure Double(Item : in out Integer)
is
begin -- procedure
Double.
Item := Item *
2;
end Double;
X : Integer := 1; -- Local variable X of type
Integer.
begin -- procedure
Compute
loop
Put(X);
New_Line;
Double(X);
end loop;
end Compute;
Let's briefly review what we've
learned so far:
Type
Extension:
Type extension in ADA 95 is achieved using ‘tagged records’. Tagged records allow the original ADA
record type to be extended from a foundation record. The foundation record must be specified
as tagged.
For example:
package people
is
type sex is (male, female);
type person is tagged record
name:string(1..35);
gender:sex;
end record;
function age (p:in person) return
natural;
end
people;
Now suppose we have another
package call “school” that uses specification from package
“people”:
packeage school
is
type janitor is new person with null
record;
type teacher isnew person with
record
subject:string(1..5);
end record;
type head_master is new teacher with
record
off_tel:natural;
room-num:natural;
end record;
end
school;
Type “janitor” is extended from
the foundation type “person.” It
has the fields “name”, “gender”, but no additional fields are added since we
wrote “ with null record”.
Type “teacher” is extended from
the foundation type “person.” The
extension “teacher” has the basic fields “name” and “gender” as the foundation
record type “person.” In addition
to the basic fields, a new field, “subject” is added. This is called type extension and is
only possible if the base or foundation type (person in this case) is declared
as tagged.
Type “head_master” is extended
from type “teacher”. Since the base
type of “teacher” is declared as tagged, it is possible to add fields to type
“head_master”. In this case, we
have added the fields “off_tel” and “room_num.”
Tagged
Private:
When using tagged private, the
foundation type must be private and allows users to extend
it.
For example:
Package new_people
is
type sex is (male, female);
type person is tagged
private;
function age (p:person) return
natural;
private
type person is tagged
record
name:string(1..5);
gender:sex;
end
record;
end
new_people;
Note that the type “person” is
tagged private. That means it
allows the user of the package “new_people” to extend the type “person” without
knowing the details of the type.
For example:
with new_people; use
new_people;
package user
is
type star is
new_person with record
cosmetic_surgery:boolean;
end
record;
…..
end
user;
Type “star” extends “new_person”
without knowing the details of the type (eg. What fields it
contains).
Polymorphism:
In ADA95, if we have a tagged type T, then we automatically have an
associated type T’class which contains the union of all types derived from the
root type T
For example, from the tagged type “person”, we have person’class which contains the union of all types derived from the root type “persion” (janitor, teacher, head_master).