Elemental functions are a neat feature of Fortran but are limited by the requirement that all arguments be scalars. Could this be relaxed to allow a mix of scalar and array arguments? A partially elemental function would be elemental for the scalar arguments, which in the caller would be scalars or conformable arrays as they are now. A function such as
elemental function moment(power,offset,x) result(y) integer, intent(in) :: power real , intent(in) :: offset real , intent(in) :: x(:) real :: y y = sum((x-offset)**power)/max(size(x),1) end function moment
would be allowed. It could be called with
moment([1,2],[0.0,1.0],x) . The result would have the same shape as the expressions passed as arguments
offset. Currently one can get similar behavior by defining a derived type with an array component and using that as a function argument, since that is considered a scalar. I don’t see why this should be necessary.