To get us going quickly, we’ll just type in a “hello, world” program in our main module. It may look like this:

In[2]:

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

To compile this code, run gnatmake -gnatyy guessing_game ﻿3 the -gnatyy flag enables all style checks, which ensures your code looks like people expect Ada code to look like – think of it a little like gofmt except built into the compiler, and then run it like you would any other binary.

In[3]:

$ gnatmake -gnatyy guessing_game gcc-6 -c -gnatyy guessing_game.adb gnatbind-6 -x guessing_game.ali gnatlink-6 guessing_game.ali $ ./guessing_game Hello, world!

I’ll quickly walk through the code line by line.

In[4]:

with Ada.Text_IO;

Any packages you want to use4 import, include in your module, you have to list at the top of your file in with statements. Statements are terminated with semicolons in Ada.

In[5]:

procedure Guessing_Game is

Procedures are functions that don’t return anything. If a procedure does not take any arguments, you don’t write the parentheses either. The main procedure in Ada does not take any arguments. The keyword is indicates that the implementation of the procedure is coming next.

In[6]:

use Ada.Text_IO;

This is the place for local declarations. Between is and begin you can declare local variables, define local types and even write local functions and procedures! In this case, we’re saying we want to import all contents of Ada.Text_IO into the local scope, so we don’t have to type Ada.Text_IO.Put_Line when we want to print something.

In[7]:

begin

Start of procedure code (and thus also end of local declarations).

In[8]:

Put_Line ( "Hello, world!" );

Ada style guides suggest a weird combination of CamelCase and snake_case for names5 I’m not even going to try to argue and it wants a space before parentheses. In general, you’ll find Ada code to be very “airy”. This is by design, albeit controversial. And yes, Ada is indented with three spaces per level.6 Oh, and Ada is case-insensitive! So pUT_LinE and put_line refer to the same thing. Of course, all of this is stylistic choice and you can ignore it if you want to but I don’t see why.

In[9]:

end Guessing_Game;

When you end a procedure, you also type the name of it. This makes it easier to debug mistakes of the kind “one closing brace too much” and gives the compiler more information to help you.