Version 1.4 of ai12s/ai12-0386-1.txt
!standard 3.5.1(14) 20-07-30 AI12-0386-1/02
!standard 4.2.1(19/5)
!standard 5.5.2(28/5)
!standard A.18.32(20/3)
!class presentation 20-06-19
!status Amendment 1-2012 20-06-19
!status WG9 Approved 22-06-22
!status ARG Approved 15-0-0 20-07-30
!status work item 20-06-19
!status received 20-06-15
!priority Low
!difficulty Easy
!qualifier Omission
!subject Still More Presentation issues
!summary
(1) Add 'Image to the example 5.5.2(25/5).
(2) Remove an extra closing parenthesis in 4.2.1(19/5).
(3) Correct the array component subtype in 4.2.1(19/5).
(4) Add a definition for Month_Name to 3.5.1(14).
(5) Add Prepend (The_Path, N); to A.18.33(20/3).
!question
(1) 5.5(28/5) says:
Put_Line("Total=" & Partial_Sum'Reduce("+", 0) &
", Min=" & Partial_Min'Reduce(Natural'Min, Natural'Last) &
", Max=" & Partial_Max'Reduce(Natural'Max, 0));
end;
The component subtype of the Partial_<something> arrays is Natural, so the
result of the reduction is also Natural. We can't concatenate a Natural to a String,
so this call is illegal. Should this be repaired? (Yes.)
(2) 4.2.1(19/5) is the body of To_Roman_Number (given as an expression function):
function To_Roman_Number (S : String) return Roman_Number is
(declare
R : constant array (Integer range <>) of Integer :=
(for D in S'range => Roman_Digit'Enum_Rep
(Roman_Digit'Value (''' & S(D) & '''))); --
begin
[for I in R'range =>
(if I < R'Last and then R(I) < R(I + 1) then -1 else 1) * R(I))]
'Reduce("+", 0)
);
The value_sequence in the square brackets has 4 opening parentheses and 5
closing parentheses. Should the last of these be removed? (Yes.)
(3) Also in 4.2.1(19/5), the array R has components of subtype Integer,
so the reduction expresion is also returning type Integer. But the result of
the function is type Roman_Number, which is a different integer type.
Should this be fixed? (Yes.)
(4) type Date declared in 3.8(27) uses type Month_Name. However, Month_Name is
not declared anywhere. Should this be fixed? (Yes.)
(5) The example in A.18.33 produces a path that does not include the last step
to the Target node. That is conventionally included in the path. Should the
example be fixed? (Yes.)
!response
(1) It appears the intent is to display the Image of these results. We can
just add 'Image to the end of each 'Reduce, as an attribute_reference is a
syntactic name and thus can be the prefix to 'Image.
(2) It appears that someone miscounted the parentheses in this example.
(3) Since attribute Enum_Rep is a universal integer attribute, we can
change the component subtype of array R to Roman_Number without any other
change. This seems to be the minimum change that fixes the type mismatch.
Alternatively, we could have surrounded the entire reduction with a type
conversion to Roman_Number. But this is more obtrusive and also fails to
illustrate the value of properly selecting types.
(4) There has been a principle in the Ada Reference Manual that if one
combined all of the declarations of all of the examples together, the result
would be compilable (that is, all types and objects used would be defined).
[Editor's note: I've added an AARM Note describing this principle following
the definition of the Example header in 1.1.2. We've referred to it for a long
time without it ever appearing in the AARM.]
While Month_Name itself is only used in type Date in 3.8(27), type Date is
used in a number of aggregate examples, including 4.3.1(25), 4.3.1(27)),
4.3.4(23/5), and 4.3.4(28/5). These examples use the enumeration literals
"July" and "Apr", which are inconsistent. Thus we also change 4.3.4(28/5) to
use "April".
(5) The result path should include the Target.
!wording
(1) Replace 5.5(28/5) with:
Put_Line ("Total=" & Partial_Sum'Reduce("+", 0)'Image &
", Min=" & Partial_Min'Reduce(Natural'Min, Natural'Last)'Image &
", Max=" & Partial_Max'Reduce(Natural'Max, 0)'Image);
end;
(2) & (3) Replace 4.2.1(19/5) with:
function To_Roman_Number (S : String) return Roman_Number is
(declare
R : constant array (Integer range <>) of Roman_Number :=
(for D in S'range => Roman_Digit'Enum_Rep
(Roman_Digit'Value (''' & S(D) & '''))); --
begin
[for I in R'range =>
(if I < R'Last and then R(I) < R(I + 1) then -1 else 1) * R(I))]
'Reduce("+", 0)
);
(4) Replace 3.5.1(14) with:
type Day is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
type Month_Name is (January, February, March, April, May, June, July,
August, September, October, November, December);
type Suit is (Clubs, Diamonds, Hearts, Spades);
type Gender is (M, F);
type Level is (Low, Medium, Urgent);
type Color is (White, Red, Yellow, Green, Blue, Brown, Black);
type Light is (Red, Amber, Green); --
Replace 4.3.4(28/5) with:
Tomorrow := ((Yesterday with delta Day => 12) with delta Month => April); --
(5) Replace A.18.33(20/3) with:
declare
N : Node := Target;
begin
Prepend (The_Path, N);
while N /= Source loop
N := Reached_From(N);
Prepend (The_Path, N);
end loop;
end;
!discussion
None.
!corrigendum 3.5.1(14)
Replace the paragraph:
type Day is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
type Suit is (Clubs, Diamonds, Hearts, Spades);
type Gender is (M, F);
type Level is (Low, Medium, Urgent);
type Color is (White, Red, Yellow, Green, Blue, Brown, Black);
type Light is (Red, Amber, Green); -- Red and Green are overloaded
by:
type Day is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
type Month_Name is (January, February, March, April, May, June, July,
August, September, October, November, December);
type Suit is (Clubs, Diamonds, Hearts, Spades);
type Gender is (M, F);
type Level is (Low, Medium, Urgent);
type Color is (White, Red, Yellow, Green, Blue, Brown, Black);
type Light is (Red, Amber, Green); -- Red and Green are overloaded
!corrigendum 4.2.1(0)
Insert new clause:
See the conflict file for the changes.
!corrigendum 4.3.4(0)
Insert new clause:
See the conflict file for the changes.
!corrigendum 5.5(21)
Insert after the paragraph:
Summation:
while Next /= Head loop -- see 3.10.1
Sum := Sum + Next.Value;
Next := Next.Succ;
end loop Summation;
the new paragraphs:
Example of a simple parallel loop:
See the conflict file for the changes.
!corrigendum A.18.33(20/3)
Replace the paragraph:
declare
N : Node := Target;
begin
while N /= Source loop
N := Reached_From(N);
Prepend (The_Path, N);
end loop;
end;
by:
declare
N : Node := Target;
begin
Prepend (The_Path, N);
while N /= Source loop
N := Reached_From(N);
Prepend (The_Path, N);
end loop;
end;
!ASIS
No ASIS effect.
!ACATS test
No ACATS tests needed for presentation issues.
!appendix
!topic Shortest_Paths example error
!reference Ada 202x RM18.32(20/3)
!from John J Cupak Jr 20-06-09
!keywords Container Example Error
!discussion
The Shortest_Paths generic package presented in A.18.32 Example of Container
Use (pages 580-581) does not return the complete path.
Using the tinyEWD.txt data file from Sedwick’s Algorithms, the correct
returned path from node 0 to node 6 should be:
0 -> 2 -> 7 -> 3 -> 6
However, the actual returned path is:
0 -> 2 -> 7 -> 3
The error lies in the Rebuild path from target to source code block, which is
published as:
19/3 -- Rebuild path from target to source.
20/3 declare
N : Node := Target;
begin
while N /= Source loop
N := Reached_From(N);
Prepend (The_Path, N);
end loop;
end;
return The_Path;
After analysis, it was determined that a Prepend (The_Path, N); statement was
missing between the begin and the while loop. The corrected version should be:
19/3 -- Rebuild path from target to source.
20/3 declare
N : Node := Target;
begin
Prepend (The_Path, N); — MISSING
while N /= Source loop
N := Reached_From(N);
Prepend (The_Path, N);
end loop;
end;
return The_Path;
****************************************************************
Questions? Ask the ACAA Technical Agent