with Ada.Text_IO; use Ada.Text_IO;
procedure Outp is
procedure Foo (A : in out Integer) is
begin
Put_Line (A'Image);
end;
A : Integer := 12;
begin
Foo (A);
end;I was told that adding the identifier to the end of blocks is just a good practice, since the compiler can tell you if you misread the nesting and wrote the wrong name.
On Twitter the other day, someone suggested that this is because, when Ada was first made, this kind of analysis was truly to expensive, and so the guarantee was not made, and they're sticking to backwards compatibility, and modern implementation should basically always warn. That seems reasonable, but I have no idea if it's correct. I assume most real-world Ada scenarios treat warnings as errors.
It was a great victory of Java and C# to require this. Java's analysis is "buggy" and C#'s is complete.
That is a bit of a theme in Java. The type inference often has the same problem.
(Although the type inference is also actually unsound)
Or like Go only taking into account C, Limbo, and CSP.
TLDR: reading uninitialized data in Ada is safer than in C.
Reading an uninitialized OUT argument is a bounded error, which is much less dramatic than C’s undefined behavior: the semantics is that you’ll read an arbitrary value (which is obviously bad as far an program intent is concerned), but otherwise the language constraints still hold.
This is very different from erroneous execution, which is very similar to the famous undefined behaviors in C, in which all bets are off and anything can happen.
Playing compiler, the output should be
You can make variables in and out by saying that (literally). This will do what Steve expected: