How is dynamic scoping in this case 'more useful'? Imagine function a written by author A and function b written by author B, both loaded into an application and each of them working independently, bound together by an api spec. Now function a uses typeset IFS="X" to set the field separator to "X" via a local variable IFS. If function b now uses "read foo1 foo2 foo3" to read a line of a database the concept of dynamic scoping *BITES*. Suddenly function b no longer works as author B intended it. Lots of surprise, lots of raised eyebrows by an unwanted interaction. Static scoping is in this case much *SAFER* because IFS is reset in function b to the (global) default. The issue isn't new but the issues with dynamic scoping are one major factor why there are so few shell function libraries: It is just hard to write such a library without running afoul dynamic scoping. Olga On Sun, Nov 14, 2010 at 12:22 AM, Harald van Dijk <harald@xxxxxxxxxxx> wrote: > On 09/11/10 23:02, Eric Blake wrote: >> >> 2. User aspect: >> Is anyone aware of a script that intentionally uses the full power of >> dynamic scoping available through 'local' which would break if scoping >> switched to static? > > FWIW, some scripts use "local IFS" to reset IFS to a sane value, and have > the shell take care of restoring it afterwards. This works with ksh's > typeset, but because of the static scoping only so long as no other shell > functions get called, or those other shell functions also take the effort to > handle IFS correctly. In the scripts I have been able to find, other shell > functions do get called, but they themselves set IFS too. Still, it may be > worth keeping in mind, if only to serve as one of the few examples of when > dynamic scoping would have been slightly more useful. > -- > To unsubscribe from this list: send the line "unsubscribe dash" in > the body of a message to majordomo@xxxxxxxxxxxxxxx > More majordomo info at http://vger.kernel.org/majordomo-info.html > -- , _ _ , { \/`o;====- Olga Kryzhanovska -====;o`\/ } .----'-/`-/ olga.kryzhanovska@xxxxxxxxx \-`\-'----. `'-..-| / http://twitter.com/fleyta \ |-..-'` /\/\ Solaris/BSD//C/C++ programmer /\/\ `--` `--` -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html