Skip to content

Commit 4c337c2

Browse files
committed
addition of a second possible behavior of present
1 parent 86c0efe commit 4c337c2

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

proposals/default_optional_arguments/proposal.txt

+24-3
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,14 @@ compatibility.
106106

107107
4.1 present()
108108

109-
When the optional dummy argument has an initializer, the function
110-
present() will return .true., even if the actual argument is not passed
111-
by the caller.
109+
There are two possible behaviors of the function present() when an
110+
initializer is provided.
111+
112+
The first behavior would be that the function present() always returns
113+
.true. when the optional dummy argument has an initializer, and
114+
independently of the fact that an actual argument is passed or not
115+
by the caller. Therefore, with such a behavior, the function present()
116+
becomes useless for optional arguments with a default value.
112117

113118
Example:
114119

@@ -120,6 +125,22 @@ Example:
120125
print*, present(b) !always .true. due to the initializer
121126
end function foo
122127

128+
The second behavior would be that the function present() returns
129+
.true. or .false. when an actual argument is passed or not by the
130+
caller, and independently of the fact that the optional dummy
131+
argument has, or hasn't an initializer.
132+
133+
A use case of this behavior of the function present() could be:
134+
135+
real function foo(a, b)
136+
real, intent(in) :: a
137+
real, intent(in), optional :: b = 1.234
138+
if (present(b)) then
139+
... !expensive input validation here
140+
end if
141+
...
142+
end function foo
143+
123144

124145
5. Further discussion
125146

0 commit comments

Comments
 (0)