Saturday 18 April 2020

Ada on the Raspberry Pi

Introduction

The computer language  known as Ada was the result of a US Department of Defense competition to develop a computer language to replace the numerous computer languages used in existing defence projects. The competition was won by a team lead by a French team lead by Jean Ichbiah.

Installation

As with installing any new piece of software , you should update and upgrade the current installation
sudo apt update
sudo apt upgrade
sudo apt-get install gnat

As of 18/04/2020 it installed version 6.1.

Hello World

For simplicity, I used the Geany Program Editor to write my first Ada program.

Create a new file called helloworld.adb, I created a folder called Ada in my Documents folder to take the code. For later work, it is best to create a folder for the source code - compiling and building create a number of files.

In the new file enter the following.
-- My first ADA program
with Ada.Text_Io;
use Ada.Text_Io;
procedure HelloWorld is
begin
   Put_Line("Hello World");
end HelloWorld;
The two hyphens start a comment.
The with tells the compiler what package to use. The contents of the package are made visible to this program by the use.
The procedure has a name (HelloWorld) and the code is bounded by the begin - end.
The put_line is a procedure from the package Ada.Text_Io that takes a string parameter and outputs the string followed by a new line character to the standard output.

Compile and Build

Geany handles all the complicated parameters for compilation and building. The options can be found under the Build menu option. Alternatively the function key F8 compiles and F9 Builds.

Execution

Though there is an execute option in the Geany Build menu, the code executes and then disappears.
To see the result of the program start a terminal window and navigate to the folder with the source code.
The executable file has no suffix but has the name of the source file. Prefix the filename with ./ and press return:
pi@somepi:~/Documents/ADA $ ./helloworld
Hello World
pi@somepi:~/Documents/ADA $ 

References

https://www.adaic.org/learn/materials/#introtoada
https://askubuntu.com/questions/421084/how-do-i-install-the-ada-compiler
http://www.getadanow.com/#get_raspberry_pi
http://www.getadanow.com/#step2
https://en.wikipedia.org/wiki/Ada_(programming_language)