Skip to content

Commit 3b03b32

Browse files
Resolve "Subprograms: Expression Functions Quiz Introduces Concepts that Have Not Been Covered"
1 parent 9ade407 commit 3b03b32

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

courses/fundamentals_of_ada/070_subprograms/08-expression_functions.rst

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,29 @@ Which statement is True?
6060

6161
A. Expression functions cannot be nested functions.
6262
B. Expression functions require a specification and a body.
63-
C. Expression functions must have at least one "return" statement.
63+
C. Expression functions must have at least one :ada:`return` statement.
6464
D. :answer:`Expression functions can have "out" parameters.`
6565

6666
.. container:: animate
6767

68-
Explanations
68+
Explanation
6969

70-
A. False, they can be declared just like regular function
71-
B. False, an expression function cannot have a body
72-
C. False, expression functions cannot contain a no :ada:`return`
73-
D. Correct, but it can assign to :ada:`out` parameters only by calling another function.
70+
A. They **can** be nested subprograms (just like any other subprogram)
71+
B. As in other subprograms, the implementation can serve as the specification
72+
C. Because they are expressions, the :ada:`return` statement is not allowed
73+
D. An expression function does not allow assignment statements, but it can call another function that is **not** an expression function.
74+
75+
.. code:: Ada
76+
77+
function Normal_Fun (Input : Character;
78+
Output : out Integer)
79+
return Boolean is
80+
begin
81+
Output := Character'Pos (Input);
82+
return True;
83+
end Normal_Fun;
84+
85+
function Expr_Fun (Input : Character;
86+
Output : out Integer)
87+
return Boolean is
88+
(Normal_Fun (Character'Succ (Input), Output));

0 commit comments

Comments
 (0)