Runtime Environments & Parameter Passing



Answer & solution
Answer: B (no official key was published)
1. Call-by-name reevaluates the actual expression i+j whenever x is used. Under the stipulated dynamic scope, name lookup uses the nearest active bindings.
2. During the first print, P's local i=10 is nearest, while j resolves to global 5. Thus x=15 and x+10=25.
3. The assignments make the active local i=200 and global j=20. The second use reevaluates i+j as 220, rather than retaining 15.
4. The output is 25,220, B. This is specifically the question's dynamic-name interpretation, not lexical capture of main's i.
Solution: In the question's dynamic-scoping, call-by-name model, the actual expression i+j is reevaluated at each use with the active dynamic bindings. At the first print, i is P's local 10 and j is the global 5, so x+10 is 25. P then changes its local i to 200 and global j to 20. The second evaluation of x gives 220. Hence B. This uses the stipulated dynamic-name lookup rather than lexical capture of the actual expression.