Jensen's Device: Difference between revisions

Added Algol W
(Added Algol W)
Line 125:
END</lang>
Output: +5.18737751763962e +0
 
=={{header|ALGOL W}}==
{{Trans|ALGOL 68}}
Algol W retained Algol 60's call by name but also offered additional parameter passing modes.
<br>This version uses call by name for the i parameter but uses a procedure parameter for the summed expression.
<br>The expression supplied in the call is automatically converted to a procedure by the compiler.
<lang algolw>begin
integer i;
real procedure sum ( integer %name% i; integer value lo, hi; real procedure term );
% i is passed by-name, term is passed as a procedure which makes it effectively passed by-name %
begin
real temp;
temp := 0;
i := lo;
while i <= hi do begin % The Algol W "for" loop (as in Algol 68) creates a distinct %
temp := temp + term; % variable which would not be shared with the passed "i" %
i := i + 1 % Here the actual passed "i" is incremented. %
end while_i_le_temp;
temp
end;
% note the correspondence between the mathematical notation and the call to sum %
write( sum( i, 1, 100, 1/i ) )
end.</lang>
{{out}}
<pre>
</pre>
 
=={{header|AppleScript}}==
3,048

edits