Procedure Parameters .
. Scope of m does not include procedure b
. within b, call h(2) activates f
. it outputs f(2) which is 2
. how is access link for activation of f is set up?
. a nested procedure must take its access link along with it
. when c passes f:
- it determines access link for f as if it were calling f
- this link is passed along with f to b
Lexical scope rules apply even when a nested procedure is passed as a parameter. In the program shown in the previous slide, the scope of declaration of m does not include the body of b. Within the body of b, the call h(2) activates f because the formal h refers to f. Now how to set up the access link for the activation of f? The answer is that a nested procedure that is passed as a parameter must take its access link along with it, as shown in the next slide. When procedure c passes f, it determines an access link for f, just as it would if it were calling f. This link is passed along with f to b. Subsequently, when f is activated from within b, the link is used to set up the access link in the activation record for f.
|