[J3] Can elemental procedure have no dummy arguments?
Daniel C Chen
cdchen at ca.ibm.com
Wed Apr 25 14:00:35 EDT 2018
Thanks Bill.
I think the question is then: Should the standard have an explicit
constraint saying an elemental procedure (function or subroutine) should
have at least one dummy argument (optional or not)?
Thanks,
Daniel
XL Fortran Development, Fortran Standard Representative
IBM Toronto Software Lab
Phone: 905-413-3056
Tie: 969-3056
Email: cdchen at ca.ibm.com
http://www.ibm.com/software/awdtools/fortran/xlfortran
From: Bill Long via J3 <j3 at mailman.j3-fortran.org>
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Bill Long <longb at cray.com>
Date: 04/25/2018 01:42 PM
Subject: Re: [J3] Can elemental procedure have no dummy arguments?
Sent by: "J3" <j3-bounces at mailman.j3-fortran.org>
> On Apr 25, 2018, at 9:22 AM, Daniel C Chen via J3
<j3 at mailman.j3-fortran.org> wrote:
>
> Hello,
>
> It seems the standard allow an elemental function to have no dummy
arguments as in
>
> [p336] 15.8.2 Elemental function actual arguments and results
> "If there are no actual arguments or the actual arguments are all scalar,
the result is scalar."
>
> Such wording begins from F2003.
>
> Q1. Is there an usage for allowing an elemental function to have no dummy
arguments? Even though the above wording could imply all dummy arguments
are optional, I still can't think of an use case.
I hadn’t thought about that before, but it appears to work.
> cat test.f90
program test
implicit none
print *, foo(3)
print *, foo([1,2,3])
print *, foo()
contains
elemental integer function foo (x)
integer,optional,intent(in) :: x
if (present(x)) then
foo = x
else
foo = -999
end if
end function foo
end program test
> ftn test.f90
> ./a.out
3
1, 2, 3
-999
I guess the usage is if you want the function to have a “default” result
value for the case that the actual is absent. Which covers the case that
the actual is a not present optional dummy in the scope where the function
is referenced.
>
> Q2. There is not other wording to say if an elemental subroutine can have
no dummy arguments or not. What is the intention of the standard?
>
Does an elemental subroutine that has no actual arguments actually do
anything useful? Usually a subroutine call with no actual arguments as
side effects such as I/O or defining variables in modules (or common blocks
for old-timey codes). Basically things that you can’t do in a PURE
subroutine. Though maybe in an IMPURE ELEMENTAL, you could do something
useful even if there are no actual arguments. Maybe some default behavior,
analogous to the function case.
Cheers,
Bill
> Thanks,
>
> Daniel
>
> XL Fortran Development, Fortran Standard Representative
> IBM Toronto Software Lab
> Phone: 905-413-3056
> Tie: 969-3056
> Email: cdchen at ca.ibm.com
> http://www.ibm.com/software/awdtools/fortran/xlfortran
Bill Long
longb at cray.com
Principal Engineer, Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9143
Cray Inc./ 2131 Lindau Lane/ Suite 1000/ Bloomington, MN 55425
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20180425/110304b0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20180425/110304b0/attachment.gif>
More information about the J3
mailing list