Skip to content

Commit f4d5747

Browse files
authored
Merge pull request #140 from jvdp1/defpresent
addition of present()
2 parents 62282eb + 4c337c2 commit f4d5747

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

proposals/default_optional_arguments/proposal.txt

+41-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,47 @@ This addition to the language would not break any existing standard
102102
conforming Fortran program, and thus preserves Fortran's backward
103103
compatibility.
104104

105-
4. Further discussion
105+
4. Related intrinsic functions
106+
107+
4.1 present()
108+
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.
117+
118+
Example:
119+
120+
real function foo(a, b)
121+
real, intent(in), optional :: a
122+
real, intent(in), optional :: b = 0
123+
print*, present(a) !.true. if an actual argument is provided
124+
!by the caller, .false. otherwise
125+
print*, present(b) !always .true. due to the initializer
126+
end function foo
127+
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+
144+
145+
5. Further discussion
106146

107147
Online discussion that led to this proposal can be found at
108148
https://github.com/j3-fortran/fortran_proposals/issue/22.

0 commit comments

Comments
 (0)