proc foo {param} {
namespace eval foo_ns {
uplevel {set foo_ns::x $param }
}
}
这看起来很丑陋。
[upvar] 不起作用,因为它无法链接到“参数”。
谢谢。
答案中的代码不起作用(tclsh8.4)
------------------------------------------
% proc bar {param} {
namespace eval foo_ns {
uplevel [list set foo_ns::x $param]
}
}
% bar 123
can't read "param": no such variable
------------------------------------------
% proc foo {param} {
set ::foo_ns::x $param
}
% foo 123
can't set "::foo_ns::x": parent namespace doesn't exist