From a93c4938569c2ca18548c94f17e91efca50cba07 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Sun, 25 Oct 2026 02:43:04 +0200 Subject: [PATCH 1/3] Correction: use a function for an empty container aggregate Return the stored empty constant through an expression function. Co-Authored-By: Codex --- .../parts/resource_management/containers.rst | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/content/courses/advanced-ada/parts/resource_management/containers.rst b/content/courses/advanced-ada/parts/resource_management/containers.rst index 33e8e3cfc..a86a3511b 100644 --- a/content/courses/advanced-ada/parts/resource_management/containers.rst +++ b/content/courses/advanced-ada/parts/resource_management/containers.rst @@ -214,7 +214,7 @@ can confirm this by running this example and seeing the :ada:`Calling Empty_Func` message, which we included in the body of the :ada:`Empty_Func` function.) -We can also use a constant for the :ada:`Empty` element instead of a function: +An :ada:`Empty` function can also return a stored constant: .. code:: ada no_button gnat=14.2.0-1 project=Courses.Advanced_Ada.Aggregates.Container_Aggregate_Empty_Const switches=Compiler(-gnat2022); :class: ada-compile @@ -223,11 +223,13 @@ We can also use a constant for the :ada:`Empty` element instead of a function: type T is private with Aggregate => - (Empty => Empty_Const, + (Empty => Empty_Func, Add_Named => Add_Named_Proc); Empty_Const : constant T; + function Empty_Func return T; + procedure Add_Named_Proc (Cont : in out T; Key : String; @@ -241,10 +243,13 @@ We can also use a constant for the :ada:`Empty` element instead of a function: Empty_Const : constant T := (Cnt => 0); + function Empty_Func return T is (Empty_Const); + end Custom_Container_Aggregates; -Here, we simply assign :ada:`Empty_Const` when an actual :ada:`Empty` is -needed. +Here, :ada:`Empty_Const` stores the empty value, and :ada:`Empty_Func` is an +expression function that returns it. We complete the function in the private +part, after the full declaration of the constant, so no package body is needed. In addition to this, we can specify a signed integer parameter |mdash| which indicates the number of components |mdash| for the :ada:`Empty` function: From be6e7153fb56fe434e71642113e9f7addde57097 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Sun, 25 Oct 2026 02:48:15 +0200 Subject: [PATCH 2/3] Correction: run the stored-empty container aggregate example - Demonstrate that an empty aggregate returns the stored empty value. - Enable the run button and remove the older GNAT pin. Co-Authored-By: Codex --- .../parts/resource_management/containers.rst | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/content/courses/advanced-ada/parts/resource_management/containers.rst b/content/courses/advanced-ada/parts/resource_management/containers.rst index a86a3511b..6166d41f5 100644 --- a/content/courses/advanced-ada/parts/resource_management/containers.rst +++ b/content/courses/advanced-ada/parts/resource_management/containers.rst @@ -216,8 +216,7 @@ can confirm this by running this example and seeing the An :ada:`Empty` function can also return a stored constant: -.. code:: ada no_button gnat=14.2.0-1 project=Courses.Advanced_Ada.Aggregates.Container_Aggregate_Empty_Const switches=Compiler(-gnat2022); - :class: ada-compile +.. code:: ada run_button project=Courses.Advanced_Ada.Aggregates.Container_Aggregate_Empty_Const switches=Compiler(-gnat2022); package Custom_Container_Aggregates is @@ -247,9 +246,22 @@ An :ada:`Empty` function can also return a stored constant: end Custom_Container_Aggregates; + with Ada.Text_IO; use Ada.Text_IO; + + with Custom_Container_Aggregates; + use Custom_Container_Aggregates; + + procedure Show_Container_Aggregate_Empty_Const is + A : constant T := []; + begin + Put_Line ("A = Empty_Const: " & Boolean'Image (A = Empty_Const)); + end Show_Container_Aggregate_Empty_Const; + Here, :ada:`Empty_Const` stores the empty value, and :ada:`Empty_Func` is an expression function that returns it. We complete the function in the private part, after the full declaration of the constant, so no package body is needed. +Initializing :ada:`A` with :ada:`[]` calls :ada:`Empty_Func`; the program prints +``A = Empty_Const: TRUE``. In addition to this, we can specify a signed integer parameter |mdash| which indicates the number of components |mdash| for the :ada:`Empty` function: From 1a0a6f416fbf2783e6c192dc1c982aea0c163055 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 30 Oct 2026 14:57:04 +0100 Subject: [PATCH 3/3] Correction: wrap the stored-empty example output - Wrap the `Put_Line` expression to respect the Advanced Ada course 50-column limit. - Validate all seven chapter examples with `--max-columns 50`. Co-Authored-By: Codex --- .../advanced-ada/parts/resource_management/containers.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/courses/advanced-ada/parts/resource_management/containers.rst b/content/courses/advanced-ada/parts/resource_management/containers.rst index 6166d41f5..c0363be43 100644 --- a/content/courses/advanced-ada/parts/resource_management/containers.rst +++ b/content/courses/advanced-ada/parts/resource_management/containers.rst @@ -254,7 +254,8 @@ An :ada:`Empty` function can also return a stored constant: procedure Show_Container_Aggregate_Empty_Const is A : constant T := []; begin - Put_Line ("A = Empty_Const: " & Boolean'Image (A = Empty_Const)); + Put_Line ("A = Empty_Const: " + & Boolean'Image (A = Empty_Const)); end Show_Container_Aggregate_Empty_Const; Here, :ada:`Empty_Const` stores the empty value, and :ada:`Empty_Func` is an