Call-by-name (source code)

= Call-by-name

<Call-by-name> passes a procedure argument so that each use of the formal parameter refers to the actual expression in its calling environment. In <ALGOL 60>, the report explains this through replacement with renaming to avoid accidental capture of identifiers. An expression can consequently be evaluated more than once.<Revised Report on the Algorithmic Language ALGOL 60 edited by Peter Naur>[§4.7.3.2, Name replacement]{ref}

Suppose the actual argument is `a[i]`. The procedure reads its name parameter, changes `i`, and reads the parameter again. With <call-by-name>, the second access can select a different <array> entry. With <call-by-value>, both accesses use the value obtained before entering the procedure. This is also different from saving the original entry's address. <Call-by-name> does not imply <lazy evaluation> with memoization: repeated evaluation can repeat both work and <side effects>.