Pass By Name
begin comment This is an example of pass-by-name.; procedure f(a, b, c); integer a, b, c; begin a := b; b := a + c; outstring(1, "c = "); outinteger(1, c); outstring(1, "\n") end; begin integer x, y; comment This one is just like call-by-reference, except for the value of c printed by the procedure.; x := 10; y := 25; f(x, y, 5); outstring(1, "x, y = "); outinteger(1, x); outinteger(1, y); outstring(1, "\n"); comment when formulas are sent, things get interesting. When the procedure changes a or b, the value of c also changes.; x := 10; y := 25; f(x, y, 2*x + y); outstring(1, "x, y = "); outinteger(1, x); outinteger(1, y); outstring(1, "\n") end end
Output:
c = 5 x, y = 25 30 c = 150 x, y = 25 100