1/9
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
2 parameter passing methods
call by value and call by reference
call by value
The actual value is passed to the formal parameter(stored in a new local variable on the stack), which acts like a local variable. Changes do not affect the original variable. It s expensive because large data structures are copied. example: Java, Scheme, pascal, C
call by reference(by variable)
a reference to the actual parameter is passed. changes to the formal parameter do affect the actual one(aliasing). 2-way transmission (from and to the procedure)
read only parameter passing
(const or final) prevents modification of the parameter and avoids unnecessary copying
call by result
An uninitialized local variable is passed. its value is copied back to the actual parameter on return. there is no link between the actual and the formal. Con: large copying cost on return.EX: ADA
Call by reference Pros and Cons
Pro: Efficient, supports returning data via parameters
Con: Complicated semantics due to aliasing
Call by value Pros and Cons
Pros: Simpler semantics and referential transparency
Cons: Cannot return data via parameters; copying cost
Call by name
The actual parameter is not evaluated before the call. Instead its text is substituted into the function body
Call by name environment
there must be passed a pair <exp, env> where exp is the unevaluated expression and env ins the environment in which to evaluate it. It s expensive because the environment must be re-evaluated every time the parameter is used . Ex: Algol
Call by name pointers
2 pointers are passed: a pointer to the expression text and a pointer to the static chain(stack environment)