Man or boy test: Difference between revisions

Added Algol W
(→‎{{header|Wren}}: Stack corruption bug now fixed.)
(Added Algol W)
Line 464:
<pre>
-67
</pre>
 
=={{header|ALGOL W}}==
{{Trans|ALGOL 60}}
Algol 60 has two parameter passing modes: by value and by name, Algol W has these plus a number of others. In Algol W, an expression is automatically converted to a procedure (by the compiler) if it is used as a parameter to a procedure that is expecting a procedure - this is used in the following. The sample below is thus similar to the Algol 68 sample above, but without the need for routine texts for the literals 1, -1, etc. as these are generated automatically.
<p>
Note that unlike Algol 60, in Algol W the result of a procedure is the final value calculated by the procedure and so the result cannot be assigned in a sub-procedure. This means the following sample is "strictly incorrect" (see the notes on the Algol 60 sample) but yields the correct result.
<lang algolw>begin
real procedure A (integer value k; real procedure x1, x2, x3, x4, x5);
begin
real procedure B;
begin k:= k - 1;
A (k, B, x1, x2, x3, x4)
end;
if k <= 0 then x4 + x5 else B
end;
write (r_format := "A", r_w := 8, r_d := 2, A (10, 1, -1, -1, 1, 0))
end.</lang>
{{out}}
<pre>
-67.00
</pre>
 
3,032

edits