rshapiro <[log in to unmask]> writes:
> The idea behing a pure procedure is that it will produce no side
> effects. For example, suppose FOO is a pure function
>
> A = 0*FOO(X)
>
> can be optimized to A = 0 safely.
That's all true, but look at the following trivial example which is
forbidden by the standard (both STOP and PRINT are not allowed), but
makes perfect sense to me:
elemental procedure one_over (y, x)
real, intent(out) :: y
real, intent(in) :: x
if (x /= 0.0) then
y = 1.0 / x
else
print *, "one_over: invalid argument: x = 0"
stop
end if
end procedure one_over
It appears that the only legal way is
elemental procedure one_over (y, x, err)
real, intent(out) :: y
real, intent(in) :: x
logical, intent(out) :: err
if (x /= 0.0) then
y = 1.0 / x
err = .false.
else
y = 0.0
err = .true.
end if
end procedure one_over
...
call one_over (y_array, x_array, err_array)
if (any (err_array)) then
print *, "one_over: invalid argument: x = 0"
stop
end if
...
which can be very tedious for more than one level of procedure calls
and many instances. (I agree that it provides more information
though, since I can find out at which position in the array the
offending value was.)
John Blair-Fish <[log in to unmask]> writes:
> My understanding was that PURE procedures could be run in
> parallel. If they were going to do I/O there would be all the
> potential problems of several instances of a procedure trying to do
> I/O to the same file or device.
That's an (unfortunately very relevant) implementation issue, that,
in the ebst of all worlds, would not compromise language design.
Cheers,
-Thorsten
--
Thorsten Ohl, Physics Department, TU Darmstadt -- [log in to unmask]
http://crunch.ikp.physik.tu-darmstadt.de/~ohl/ [<=== PGP public key here]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|