edited by
13,147 views

1 Answer

Best answer
6 votes
6 votes

Deep/shallow binding makes sense only when a procedure can be passed as an argument to a function.

  • Deep binding binds the environment at the time a procedure is passed as an argument.
  • Shallow binding binds the environment at the time a procedure is actually called. 

1. Deep binding.

f() gets the environment of main, since f() is passed as an argument in main. At the time of passing, x in main (the global x) is 5. So, f changes the global x to 55, and g prints the local x as 10.

2. Shallow binding.

f() gets the environment of g at the time it is called. So, f changes the x in g to 10+50 = 60, and g prints the value 60.

selected by

Related questions