2
votes

I am currently doing the Ada tutorial from learn.adacore.com, and I am now at the second example: reading and outputting an integer. Since copy-pasting is for people who don't want to learn the syntax, I manually typed out most of the code (Some of it was generated by gnat-gps, but I'm now using vim).

I compiled and ran the program, and surprisingly, the second line of output is indented by roughly one tab. Why?

Here's the code:

With Ada.Text_IO;
Use Ada.Text_IO;
With Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;

procedure Main is
    N : Integer;
begin
   --  Insert code here.
    Put("Enter an integer value: ");
    Get(N);
    if N>0 then
        Put (N);
        Put_Line(" is a positive number");
    end if;
end Main;

(how do I get syntax highlighting?)

Here is a sample of the output (the first 1 being input):

Enter an integer value: 1
          1 is a positive number
1
I edited to add syntax highlightling. I think that on Github Iā€™d have said ```ada instead of ``` lang-ada. ā€“ Simon Wright
The syntax highlighting doesn't seem to work very well. I've taken a look, and it is due to the syntax highlighter lacking support for Ada. It is code-prettify. There was already a patch for providing support for Ada, so I've updated it and made a pull request.Now it only needs that Google process the 44 pending pull requests... ā€“ Gneuromante

1 Answers

6
votes

The Put procedure from Ada.Integer_Text_IO uses a default field width padded with spaces. The specification for that procedure is defined in the Ada Language Reference Manual as:

procedure Put(Item  : in Num;
              Width : in Field := Default_Width;
              Base  : in Number_Base := Default_Base);

The Width and Base parameters are given default values. Your call to Put only supplied a value for the formal parameter Item. To eliminate the left padding simply specify a desired width. I suggest you use Ada named notation for the call as in

Put(Item => N, Width => 1);