|
Probably the easiest way to understand the effect of call by name is to think of it as a sort of sanitized macro processing.
A, i, k are all global variables. Suppose that before the call to P, i=17 and k=30. First, rename the local copy of i in the body of P:
Then substitute in the actual parameters: Finally, execute the code above, as if it occurred at the location of the call. Afterwards, i=17, k=31, and A[48]=33. The change to the local value of m has no impact outside of the procedure body.
The few languages (particularly ALGOL) that offer call by name usually implement it by passing thunks---procedures that return the l values of the actual parameters. Mike O'D. |
to: