What is Ada
Ada is a programming language that encourages modern software engineering principles, and it is mainly used for safety-critical applications like airplanes, missile control systems, nuclear plants among others. The Department of Defense(DOD) developed ADA in the 1970s to improve the quality of software applications.
"Ada encourages good programming practices by incorporating software engineering principles with strong typing, modularity, portability, reusability and readability..."[1]
"Is an Internationally standardized, general purpose programming language used in a wide variety of applications..." [1]
Ada Past, Present and Future
Below is a link to 4 videos of a lecture by professor Rober Dewar (biography), given at MIT.
If you are familiar with programming languages you will enjoy these videos
Basic Structure of Ada Programs + some Examples
Ada programs are organized in packages. You can use predefined packages or you can just create your own.
There are many key concepts you may want to understand first by reading more detailed tutorials, like packages, generics, tasks, types and others.
Through the rest of this tutorial i will assume the use of the GNAT compiler to run Ada programs.
1). - STRUCTURE OF PACKAGESIn Ada you always have 2 files for each package:
-the specification file - with extension ads
-the implemention file - with exension adb
The logic is very simple: The variables, types and subprograms (subprocedures) declarations go in the specification file . In the implementation file you put the code (body) for the procedures and functions.
Below are some really simple programs. You can see instructions on how to compile them in this same tutorial (here)2). - HELLO WORLD EXAMPLE
For the hello world example we don't need to create neither a package or a specification file, since it's just a procedure. It's important to note that file Hello.adb must only have 1 procedure, because, since it's not a package it must have only 1 compilation unit (the single procedure). Furthermore, the single procedure must have the same name as the file itself.
Hello.adb (source code)
2). - GENERIC Quadratic SORTING ALGORITHMFor the generic sorting program i wrote i very simple generic package named "sort" (with adb and ads files) plus a "driver" package which instantiate the generic packages 'sort' and 'list'.
I also wrote a package named LIST to store a LIST of anything (not only numbers).
The generic SORT pagckage can sort anything if it's told how to compare 2 values and how to swap them !!.
You may compile everything by doing gnatmake runit.adb and executing the generated program: runit.exe
Packages are SORT, LIST, DRIVER and one single subprogram RUNIT. I haven't tested these files in UNIX yetsort.ads
sort.adb
- Generic package to sort anything (quadratic sort)
list.ads
list.adb
- Generic package to mantain a list of anything and access its elements
driver.ads
driver.adb
- Instantiate the generic packages LIST and SORT appropiately
runit.adb - Invokes the driver main method to begin demonstration
How to compile and run Ada Programs
In order to run Ada Programs you need to download an ADA compiler. I would recommed GNAT1. Download the GNAT compiler and install it
You can download the GNAT compiler for Windows from the following ftp urls(Note the 2 different versions, one is for NT)
ftp://cs.nyu.edu/pub/gnat/3.15p/winnt/gnat-3.15p-nt.exe
ftp://cs.nyu.edu/pub/gnat/3.15p/winnt/gnatwin-3.15p.exe
3.Compile your adb file
Every package has 2 files, the adb (implementation) and ads (specification) files. In order to compile a package just type:
> gnatmake package_name.adb.
For instance, in the code examples above, to compile the SORT package i would do
> gnatmake sort.adb
THen the compiler will create other files like the sort.o and sort.ali files. If the compiled code will be an executable i will create an .exe file too.
Just make sure the gnatmake program is in your PATH. Suppose you installed GNAT in c:\GNAT. To add gnatmake to the PATH do:
set PATH=%PATH%;c:\GNAT\bin
[1] www.adahome.com