Like everything else, Dynamic Scoping is merely a tool. Used well it can make certain tasks easier. Used poorly it can introduce bugs and headaches.
I can certainly see some uses for it. One can eliminate the need to pass variables to some functions.
For instance, I might set the display up at the beginning of the program, and every graphic operation just assumes this display.
If I want to set up a window inside that display, then I can 'add' that window to the variable stack that otherwise specifies the display, and any graphic operations performed while in this state will go to the window rather than the display as a whole.
It's a contrived example that can be done equally well by passing parameters to functions, but when you look at some of the code this sort of task generates you realize that global variables are really a much easier way to go, and dynamic scoping gives you a lot of the sanity of global variables with the flexibility of function parameters.
-Adam
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…