Will Coleda writes: > Can someone explain to me the lexical pad stack and static nesting > depth? > > I'm trying to write "global" for tcl, and trying to pull out a variable > from the outermost pad, and failing to find it. - I'm fairly certain > this is because I'm abusing "new_pad" and "store_lex" (always using 0 > as the static nesting depth). Works fine when all I care about is the > current pad - but getting to variables elsewhere in the pad stack > results in a lexical not found error. > > Do I need to manually keep track of my nesting depth? If so, what's the > rationale? (why have the stack if you also have the nesting depth?)
Because the stack is dynamic, while the nesting depth is static/lexical. That is, you keep track of the nesting depth only at compile-time. If you want globals to just be lexicals at the top level, that's fine. Just do a C<new_pad 0> at the beginning of your program, and then C<store_lex 0> for each global. I don't know TCL, but if you have other lexical scopes, start at C<new_pad 1> and use C<find_lex -1> for all lexicals. But to play nice with other languages, you should probably use C<store_global> and C<find_global> for globals. Luke > Heading off to experiment... > > -- > Will "Coke" Coleda will at coleda > dot com >