I have a little problem which I cannot explain at the moment. I created a minimalistic code snippet to show my problem or lack of understanding how tcl namespaces are working.
So I have the file test.tcl:
namespace eval test {
proc print {file_name} {
namespace inscope ::test2 {
printFileName $::test::file_name
}
}
}
namespace eval test2 {
proc printFileName {file_name} {
puts $file_name
}
}
Than I use tclsh and run:
source test.tcl
test::print test.dat
Which returns:
can't read "::test::file_name": no such variable
Why is that should the argument of test::print not be in the ::test namescope? I have an easy workaround with set ::test::filename $filename before namespace inscope {}.
But I am not satisfied since I miss something here.
I cannot just run ::test2::printFileName $file_name since my real world code is more complex and does not run just one command it sources a list of commands which are all in a different namespace.
namespace inscopeisn't intended for direct usage by applications? What are you really trying to do? The trivial way to do this would be to use a proc and just pass the value instead of running code in a naked namespace. - schlenk