From 282896112eb7935dc8ae80720fd262cf65406504 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Sun, 25 May 2025 17:50:32 +0200 Subject: [PATCH 1/3] Editorial change: correcting button of code block --- content/courses/intro-to-ada/chapters/subprograms.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/courses/intro-to-ada/chapters/subprograms.rst b/content/courses/intro-to-ada/chapters/subprograms.rst index ab9b03fc0..4e0451081 100644 --- a/content/courses/intro-to-ada/chapters/subprograms.rst +++ b/content/courses/intro-to-ada/chapters/subprograms.rst @@ -212,7 +212,7 @@ call cannot be ignored; that is, a function call cannot be used as a statement. If you want to call a function and do not need its result, you will still need to explicitly store it in a local variable. -.. code:: ada run_button project=Courses.Intro_To_Ada.Subprograms.Quadruple +.. code:: ada compile_button project=Courses.Intro_To_Ada.Subprograms.Quadruple :class: ada-expect-compile-error function Quadruple (I : Integer) From 59f57b950c16bf61dfda9057daebf11016352027 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Sun, 25 May 2025 17:50:53 +0200 Subject: [PATCH 2/3] Editorial change: adding function declaration --- content/courses/intro-to-ada/chapters/subprograms.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/content/courses/intro-to-ada/chapters/subprograms.rst b/content/courses/intro-to-ada/chapters/subprograms.rst index 4e0451081..bac35a05e 100644 --- a/content/courses/intro-to-ada/chapters/subprograms.rst +++ b/content/courses/intro-to-ada/chapters/subprograms.rst @@ -215,6 +215,9 @@ to explicitly store it in a local variable. .. code:: ada compile_button project=Courses.Intro_To_Ada.Subprograms.Quadruple :class: ada-expect-compile-error + function Quadruple (I : Integer) + return Integer; + function Quadruple (I : Integer) return Integer is From 597b30b7c6391e962420d743a57da9f2437237c5 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Sun, 25 May 2025 17:52:32 +0200 Subject: [PATCH 3/3] Improving code and description of Quadruple function --- .../courses/intro-to-ada/chapters/subprograms.rst | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/content/courses/intro-to-ada/chapters/subprograms.rst b/content/courses/intro-to-ada/chapters/subprograms.rst index bac35a05e..fa41c4ae0 100644 --- a/content/courses/intro-to-ada/chapters/subprograms.rst +++ b/content/courses/intro-to-ada/chapters/subprograms.rst @@ -227,17 +227,23 @@ to explicitly store it in a local variable. return I * 2; end Double; - Res : Integer := Double (Double (I)); - -- ^ Calling the Double - -- function + Res : Integer; begin - Double (I); + Double (Double (I)); -- ERROR: cannot use call to function -- "Double" as a statement + Res := Double (Double (I)); + -- OK: return value of Double is + -- assigned to Res + return Res; end Quadruple; +A statement such as :ada:`Double (Double (I));` is wrong because we're not +assigning the return value to a variable |mdash| we can correct this statement +by writing :ada:`Res := Double (Double (I));`. + .. admonition:: In the GNAT toolchain In GNAT, with all warnings activated, it becomes even harder to ignore the