I've check wikipedia, and googled but I still can't wrap my mind around how pass-by-name works in ALGOL 60.
相关问题
- Pythonic Way To Check for A Parameter Type
- passing search parameter through jquery
- ISCC - /D compiler-parameter seems to have no effe
- putc needs stdout, vs puts
- VBA passing date parameters to SQL Server stored p
相关文章
- If CancellationToken is a struct and is passed by
- Accessing variables in a function within a functio
- Pass-by-value (StringBuilder vs String) [duplicate
- History of access control modifiers such as public
- passing arguments in google apps script
- What came first: git subtree merge strategy or git
- Can't pass a script block as a parameter to po
- Detemine the previous page (i.e. referrer) in jQTo
I found a good explanation at Pass-By-Name Parameter Passing. Essentially, the body of a function is interpreted at call time after textually substituting the actual parameters into the function body. In this sense the evaluation method is similar to that of C preprocessor macros.
By substituting the actual parameters into the function body, the function body can both read and write the given parameters. In this sense the evaluation method is similar to pass-by-reference. The difference is that since with pass-by-name the parameter is evaluated inside the function, a parameter such as
a[i]
depends on the current value ofi
inside the function, rather than referring to the value ata[i]
before the function was called.The page I linked above has some more examples of where pass-by-name is both useful, and dangerous. The techniques made possible by the pass-by-name are largely superseded today by other, safer techniques such as pass-by-reference and lambda functions.
Flatlander has an illuminating example of how it works in Scala here. Suppose you wanted to implement while:
Scala is not Algol 60, but maybe it sheds some light.