Jensen's Device: Difference between revisions

m
(→‎{{header|Forth}}: Add Fortran.)
Line 403:
Here, type declarations have been omitted to save space because they won't help. Although variable <code>I</code> in the calling routine will have its value adjusted as the DO-loop in SUM proceeds (the parameter being passed by reference), this won't affect the evaluation of 1.0/I, which will be performed once using whatever value is in the caller's variable (it is uninitialised) then the function is invoked with the address of the location containing that result. The function then will make many references to that result, obtaining the same value each time. The fact that the caller's <code>I</code> will be changed each time doesn't matter.
 
Fortran does offer a facility to pass a function as a parameter using the EXTERNAL declaration, as follows - SUM is a F90 library function, so a name change in theto followingSUMJ: <lang Fortran> FUNCTION SUMJ(I,LO,HI,TERM) !Attempt to follow Jensen's Device...
INTEGER I !Being by reference is workable.
INTEGER LO,HI !Just as any other parameters.
1,220

edits