Re: [stack] Re: Parameters: ordered versus named
John Cowan <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
pml060912 scripsit: > That looks like something I came across in P.J.Brown's "Writing > Interactive Compilers and Interpreters", although I forget if he > stated it explicitly or just implied it. In essence, he suggested > handling parameters and local variables by a "don't care" method, in > which they were really global variables like any other, only their > values were stacked/reinitialised and then restored on call/return. That's dynamic scoping (not to be confused with dynamic *typing*) and it is a Really Really Bad Idea, because reasoning about the behavior of programs becomes insanely difficult. You wind up not being able to know where the value of a variable is set unless you know the exact path by which it was called, and no procedure can guarantee that the values of its parameters are safe from tampering unless it never calls any other procedure. What's more, that particular *implementation* of dynamic scoping (known as "shallow binding") only works in a single thread of control; if there are multiple threads, it goes horribly wrong in all sorts of ways. Lexical scoping, in which variables only exist within the particular portion of the program that declares them, is a far superior regime. There are occasional uses for dynamic scoping here and there, and some languages support it as an alternative to lexical scoping for restricted use (Perl and Common Lisp, notably; also because of backward compatibility). But it's hard to believe that any modern work on interpreters would recommend it. -- "Well, I'm back." --Sam John Cowan <[email protected]>