Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!hc!lanl!jlg From: jlg@lanl.gov (Jim Giles) Newsgroups: comp.lang.fortran Subject: Re: Side Effects of FORTRAN Functions Message-ID: <4153@lanl.gov> Date: 24 Sep 88 21:43:19 GMT References: <15436@ames.arc.nasa.gov> Organization: Los Alamos National Laboratory Lines: 34 From article <15436@ames.arc.nasa.gov>, by lamaster@ames.arc.nasa.gov (Hugh LaMaster): > [...] > The random number generator is the usual example of something that produces > different results depending on which call it is. If I understand the > description properly, it is now prohibited to implement a random number > generator as a function: it should be a subroutine. Is this correct? > (I don't have a problem with it- other than all those old codes which use > x=ranf(i) :-) ). Functions (as a long argument in this newsgroup has just concluded) may have side effects. The problem is that they may not have side effects that effect any other value in the same statement in which they occur (in this rule, the conditional expression in an IF statement is regarded as separate from the statement that the If guards). For example: x = ranf(i) y = ranf(i) + x The above is legal. y = ranf(i) + ranf(i) This is illegal if ranf has side effects. I would argue to the Fortran 8x committee that there should be a 'side effects' flag on the EXTERNAL statement and that the RANDOM intrinsic should be a function with side effects. My comment is that if the function was explicitly flagged as a function _with_ side effects, the second example above would still be legal and the processor would be required to call twice (in left to right order). The 8x proposal introduces RANDOM as a subroutine intrinsic instead. J. Giles Los Alamos