An alternative to static binding is dynamic binding, in which the function body is evaluated in an
Question:
An alternative to static binding is dynamic binding, in which the function body is evaluated in an environment obtained by extending the environment at the function call point (instead of the environment at the function declaration point that is used for static binding).
Extend FungLang with a dynamic call expression that has the syntax ’(’ ’dynamic’ expr expr* ’)’. A dynamic call expression is evaluated using dynamic binding.
The following examples illustrate the difference between dynamic and static bindings during function calls. Consider the program here:
The value of this program is 0. In the expression given here, variable a is bound to 3.
Now consider another version of the program that uses dynamic call expression:
The value of this program is 2. Here, variable a is bound to 5.
Consider another program that uses static binding only:
The value of this program is 6. Here, variable a is bound to 3.
If the program used dynamic binding, since the variable a will be bound to 5, the value of this program will be 8.
Step by Step Answer:
An Experiential Introduction To Principles Of Programming Languages
ISBN: 9780262045452
1st Edition
Authors: Hridesh Rajan