- Preamble
- A primer on "call-by-reference" vs "call-by-value"
- BAM HOWTO
Preamble
In function and subroutine calls,
a variable as an argument
is always "called by reference"
and never "called by value".
A primer on "pass-by-reference" vs "pass-by-value"
Call by reference (or pass by reference) is an evaluation strategy where a parameter is bound to an implicit reference to the variable used as argument, rather than a copy of its value. This typically means that the function can modify (i.e., assign to) the variable used as argument—something that will be seen by its caller.
In call by value (or pass by value), the evaluated value of the argument expression is bound to the corresponding variable in the function (frequently by copying the value into a new memory region). If the function or procedure is able to assign values to its parameters, only its local variable is assigned—that is, anything passed into a function call is unchanged in the caller's scope when the function returns.
BAM HOWTO
Call by reference
DIM a$ = "Howdy"FUNCTION hello$( p$ )p$ = p$ + " there"hello$ = p$END FUNCTIONPRINT "a$: " + a$PRINT "result of hello$( a$ ): " + hello$( a$ )PRINT "a$: " + a$
Call by value
DIM a$ = "Howdy"FUNCTION hello$( p$ )p$ = p$ + " there"hello$ = p$END FUNCTIONPRINT "a$: " + a$PRINT "result of hello$( a$ ): " + hello$( ( a$ ) )PRINT "a$: " + a$